Change SharePoint 2007 My Site URL

A little while back I renamed all URL’s within my SharePoint 2007 virtual environment. You can view my posting here. When it came to viewing users My Site, the new URL did not update after making changes to the Alternate Access Mappings within Central Administration.

So if you have the same problem or if you just need to change your My Site URL, here is a tutorial on how to fix this problem:

  1. Go to “Alternate Access Mappings” in SharePoint Central Administration > Operations. Click on the URL that corresponds to your My Site. This will take to you to the “Edit Internal URLs” page, allowing you to modify the My Site URL.

Alternate AccessMappings

Edit Internal Urls

  1. Go to “My Site Settings” which can be found in the Shared Service you configured in Shared Services Administration. Again, enter your new My Site URL.

My Site Settings

  1. Modify your IIS site host header value to match the URL your entered in Central Administration.
  2. Carry out an iisreset.

Cannot View SharePoint Intranet in Internet Explorer, Firefox is fine

I created a SharePoint 2007 installation on a Development Virtual Server. The installation and configuration of SharePoint was no problem. It actually went quite smoothly compared to my previous attempts. Lucky me! I thought to myself: “Man, things can’t get better than this”.

But I then encountered a small hitch. For some reason, I could not view my intranet through Internet Explorer. The login popup box kept of appearing even though my user credentials were correct. I had no problem accessing my Intranet in Firefox. As much as I love to use Firefox (because it is such an awesome browser), some SharePoint features are restricted when a non-IE browser is used.

The first thing I did was to add my SharePoint intranet URL to my Local Intranet trusted sites in Internet Explorer settings. From looking on the Internet, this has worked for some SharePoint developers. However, this did not fix my problem.

Add to trusted sites

This confirmed that Internet Explorer is not passing my login credentials to Active Directory causing problems when it came to authentication. I started snooping around Internet Information Services and viewed the Authentication Settings: Directory Security tab > Authentication and Access Control > Edit.

I changed my authentication in IIS for all my intranet web sites: Central Administration, Main Portal and My Site. By default, the IIS Authentication methods were set to Enable Anonymous Access and Integrated Windows Authentication. I removed these options and just selected: Basic Authentication.

Authentication Methods

After you have changed these settings just carry out an iisreset.

Custom SharePoint 2007 Bulk Document Uploader

I have noticed that one of many reasons clients like to get on to the SharePoint bandwagon is to use its detailed Document Management features to control the life cycle of each individual document within their organisation.

This got me thinking. Most organisations have hundreds, if not thousands of documents they would like to move from their networked storage devices to the SharePoint 2007 platform. It would be time consuming to upload all these documents to a document library. So I decided to create a C# application that would allow me to upload multiple files from a folder on a PC to a document library web part of my choice.

Just to note, this program I created has not been tested to upload documents in their thousands. I have tested uploading over 100 documents successfully. But feel free to modify my code to work more efficiently! ;-)

SharePoint Document Uploader

As you can see from my program above, I have managed to upload numerous documents from “Z:\My Received Files” to a document library called “Shared Documents”.

SharePoint Document Library

I created my program by using the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using System.IO; 
 
namespace MOSSDocumentLibraryUploader
{
    public partial class frmHome : Form
    {
        public frmHome()
        {
            InitializeComponent();
        }
  
        private void frmHome_Load(object sender, EventArgs e)
        {
            ddlDocumentLibList.Enabled = false;
            ddlSubSites.Enabled = false;
        }
 
        private void btnStartUpload_Click(object sender, EventArgs e)
        {
            lstUploadedDocuments.Items.Add(String.Format("Upload operation started at {0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString()));
 
            //Start uploading files
            try
            {
                //Get site collection, website and document library informationn
                SPSite intranetSite = new SPSite(txtIntranetUrl.Text);
                SPWeb intranetWeb = intranetSite.AllWebs[ddlSubSites.SelectedItem.ToString()];
                SPList documentLibrary = intranetWeb.Lists[ddlDocumentLibList.SelectedItem.ToString()];
 
                intranetWeb.AllowUnsafeUpdates = true;
                intranetWeb.Lists.IncludeRootFolder = true;
 
                //Start iterating through all files in you local directory
                string[] fileEntries = Directory.GetFiles(txtDocumentDirectory.Text);
 
                foreach (string filePath in fileEntries)
                {
                    SPFile file;
 
                    //Get file information
                    FileInfo fInfo = new FileInfo(filePath);
 
                    Stream fileStream = new FileStream(filePath, FileMode.Open);
 
                    //Load contents into a byte array
                    Byte[] contents = new Byte[fInfo.Length];
 
                    fileStream.Read(contents, 0, (int)fInfo.Length);
                    fileStream.Close();
 
                    //Upload file to SharePoint Document library
                    file = intranetWeb.Files.Add(String.Format("{0}/{1}/{2}", intranetWeb.Url, documentLibrary.Title, fInfo.Name), contents);
                    file.Update();
 
                    lstUploadedDocuments.Items.Add(String.Format("Successfully uploaded: {0}", fInfo.Name));
 
                    lstUploadedDocuments.Refresh();
                }
 
                //Perform clean up
                intranetWeb.Dispose();
                intranetSite.Dispose();
 
                lstUploadedDocuments.Items.Add(String.Format("Operation completed at {0}", DateTime.Now.ToLongTimeString()));
            }
            catch (Exception ex)
            {
                lstUploadedDocuments.Items.Add(String.Format("Error: {0}", ex));
            }
        }
 
        private void btnCancelUpload_Click(object sender, EventArgs e)
        {
            lstUploadedDocuments.Items.Add(String.Format("Upload operation cancelled at {0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString()));
        }
 
        private void txtDocumentDirectory_Validating(object sender, CancelEventArgs e)
        {
            if (((TextBox)sender).Text == "")
            {
                MessageBox.Show("You must enter an upload directory.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!Directory.Exists(((TextBox)sender).Text))
            {
                MessageBox.Show("Document upload directory does not exist.", "Directory Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 
        private void txtIntranetUrl_Validating(object sender, CancelEventArgs e)
        {
            if (((TextBox)sender).Text == "")
            {
                MessageBox.Show("You must enter a intranet url.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void ddlSubSites_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ddlDocumentLibList.Enabled = true;
 
                //Get site collection, website and document library informationn
                SPSite intranetSite = new SPSite(txtIntranetUrl.Text);
                SPWeb intranetWeb = intranetSite.AllWebs[ddlSubSites.SelectedItem.ToString()];
 
                intranetWeb.Lists.IncludeRootFolder = true;
 
                //Iterate through all document libraries and populate ddlDocumentLibList
                foreach (SPList docList in intranetWeb.Lists)
                {
                    ddlDocumentLibList.Items.Add(docList.Title);
                }
            }
            catch
            {
                ddlDocumentLibList.Enabled = false;
            }
        }
 
        private void txtIntranetUrl_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ddlSubSites.Enabled = true;
                ddlDocumentLibList.Enabled = true;
 
                //Get site collection, website and document library information
                SPSite intranetSite = new SPSite(txtIntranetUrl.Text);
 
                //Iterate through all sites and propulate ddlSubSites
                foreach (SPWeb web in intranetSite.AllWebs)
                {
                    ddlSubSites.Items.Add(web.Url.Replace(txtIntranetUrl.Text, ""));
 
                    //Iterate through child sites
                    foreach (SPWeb childSite in web.Webs)
                    {
                        ddlSubSites.Items.Add(childSite.Url.Replace(txtIntranetUrl.Text, ""));
                    }
                }
            }
            catch
            {
                ddlSubSites.Enabled = false;
                ddlDocumentLibList.Enabled = false;
            }
        }
    }
}

It would have been really cool if my program only listed Document Libraries instead of all lists within a portal site. Unfortunately, I could not find any code to get a list of type Document Library. If anyone knows how to do this, I would be grateful if you could post some code.

If you have any questions on the code or know of a better (free) solution out there, please leave a comment.

Rename SharePoint Host Headers and Change Database Server Name

I currently have a SharePoint 2007 demonstration setup on a development environment. The SharePoint 2007 installation was originally setup for a specific client. So the host headers, computer name and farm credentials contained the client name. This all had to be changed. Carrying out another installation of SharePoint was something I did not want to do since I wanted to retain all the dummy data and sites.

You might be thinking: Why don’t I just change the host headers with the new client name? Well that’s because I am a bit OCD and I like everything to be consistent. Tongue out

To rename, carry out the following. But remember to carry out these steps exactly because you might come across the problem I did where I couldn’t get to Central Admin or view my Intranet:

  1. Go to Central Admin > Operations > Alternate Access Mappings.
  2. Change the host headers as required.
  3. If you changed the name of the server carry out the following command:

    stsadm -o renameserver -oldservername <oldname> -newservername <newname>
    
  4. Rename the server to a new server name by going to My Computer > Properties > Computer Name and restart.
  5. After restart you will need to update the farm login credentials since the computer name has been changed from Steps 3 and 4. If you do not update the farm credentials, you will get the dreaded “Cannot connect to database” message when trying to view your Intranet.

    stsadm -o updatefarmcredentials -userlogin <domain\user> -password <password>
    
  6. Change the site names in IIS. This site names will need to reflect the changes you made in Step 1.
  7. Change the host headers in the host file (C:\Windows\System32\drivers\etc\hosts).

Left Navigation Site Links Not Appearing In MOSS 2003

If any of you have come across a problem in SharePoint 2003 whereby some users are not able to see a link to an area within the main portal page, the solution couldn't be even easier. Ensure all users required to access the area are setup with access rights for that area. I always thought that even if a user does not have access to an area the link will always be shown in the navigation within the main portal site. Obviously I was wrong. Silly me!

Apply Theme To All Sites In Sharepoint 2007

After I designed a theme to my SharePoint 2007 site I came across a small problem. Well it was not exactly a problem it was more of a hassle I encountered. The current SharePoint Intranet I was working on contained quite a lot of sites and I didn't want to change the site settings within each site in order to change the theme. Thankfully, SharePoint 2007 allows you to apply a Custom CSS from your theme.

In order to change the theme across the whole SharePoint Intranet carry out the following:

  1. View the source of main portal homepage and look for a line which looks something like this:
<link rel="stylesheet" type="text/css" id="onetidThemeCSS" href="/_themes/Intranet/Intr1011-65001.css?rev=12%2E0%2E0%2E4518"/> 
  1. In Site Settings click on Masterpage and scroll down to the bottom of the page.
  2. Select the "Specify a CSS file to be used by this publishing site and all sites that inherit from it" radio button.
  3. Use the link from the CSS HTML tag above excluding anything after the query string. For example: ""/_themes/Intranet/Intr1011-65001.css".

Now the theme should be applied throughout the site. You can change the link for the Custom CSS by changing the directory path.

Duplicate ID on Sequence [Microsoft.Sharepoint.Portal.Upgrade.FarmSequence]

Over the last couple of months I have been involved in upgrading our current MOSS 2003 Intranet to MOSS 2007. All I can say that it has been eventful to say the least with numerous errors popping up left right and center. I am sure I will be posting more in future regarding my Sharepoint upgrade experience.  Anyway, back to this post. When I attempted to add a content database to my MOSS 2007 Intranet I got the following error:

"Duplicate ID on sequence [Microsoft.Sharepoint.Portal.Upgrade.FarmSequence]"

Interesting...

The cause of this error resides in the Upgrade Definition files located in  "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG\UPGRADE" directory. The Upgrade Definition files tell Sharepoint where to dump the old content in the new database during the upgrade process. Even though the error message is not helpful in any shape or form, the solving this error is not too bad.

Locate the following two XML files within the UPGRADE directory: SPSUpgradePremium.xml and SPSUpgrade.xml. Then all you need to do is delete the following line that looks something like this in both files:

<Assembly Name="Microsoft.SharePoint.Portal.Upgrade,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c,Custom=null">
    <Order>5</Order>
</Assembly>

I just hope the other Sharepoint upgrade errors that appear will be more straight forward...