Archive for February, 2009

How to Change the IIS Path for a SharePoint Web Application

Posted by mjimison on February 26, 2009
C#, PowerShell, SharePoint / 7 Comments

When creating a new web application in SharePoint, you choose the physical location of where the IIS website will be created. Once the application is born, however, there is no longer an option to change this path in Central Administration. You can very easily change it in IIS (by going to your website’s Properties -> Home Directory -> Local Path), but once this is done, you will start running into trouble, as solution deployments will point to the web.config file at the old location.

Three quick steps need taken to successfully move the web application:

  1. Copy the current directory’s contents into your new directory
  2. Make the change to the website’s local path in IIS (as described above)
  3. Update the SharePoint web application to point to the new path

Note: If you have multiple servers in your farm, steps 1 and 2 will need made on each web server, but step 3 will only need done once.

The third step can be done without having to extend the site. Here are a couple options.

Option 1: C# Console Application (Reference Microsoft.SharePoint.dll)

using System;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
 
namespace IisPath
{
  class Program
  {
    static void Main(string[] args)
    {
      try
      {
        //Open the site your web application hosts
        using (SPSite site = new SPSite("http://yoursite.com"))
        {
 
          //Grab a reference to the site's web application's IIS Settings
          //Change SPUrlZone if application is not in default zone
          SPIisSettings iisSettings = site.WebApplication.IisSettings[SPUrlZone.Default];
 
          //Point to your new path
          iisSettings.Path = new System.IO.DirectoryInfo(@"D:\wss\VirtualDirectories\yoursite.com");
 
          //Call the Update method of the web application
          site.WebApplication.Update();
 
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
      }
    }
  }
}

Option 2: PowerShell Script

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 
#Point to the site your web application hosts to grab a reference to the web application
$SPSite = new-object Microsoft.SharePoint.SPSite("http://yoursite.com")
$WebApp = $SPSite.WebApplication
 
#Change SPUrlZone if not in default zone
$IISSettings = $WebApp.IisSettings[[Microsoft.SharePoint.Administration.SPUrlZone]::Default]
 
#Point to your new directory
$IISSettings.Path = "D:\wss\VirtualDirectories\yoursite.com"
 
#Update Web Application
$WebApp.Update()
$SPSite.Dispose()

I hope this has been helpful, and as always, thank you for reading.

Cheers.

Share this post:

  • email
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • Google Bookmarks
  • StumbleUpon

What this Blog Might Do

Posted by mjimison on February 24, 2009
General, SharePoint / No Comments

Being in web development for over 5 years, I often wonder why its taken me so long to start a blog.

The answer is simple, though: greed

I’ve been spending my time reading great blogs. I’ve been far more concerned with trying to pick something up, than to put something out. However, there have been many times I’ve found a ’starting point’ that had 60-70% of what I needed, but not everything. With SharePoint development gaining momentum, I thought a new blog would be a good opportunity to:

  1. Expand on ideas initially presented on other blogs
  2. Share solutions I’ve come up with on projects related to my work at Interactive Intelligence
  3. Wrap things up into solutions that non-developers will feel comfortable deploying

I’ve got experience in other technologies related to web development, and so from time to time, when appropriate, I may branch away from SharePoint to hit up related topics such as C#, ASP.Net, JavaScript, CSS, and more. However, my goal here is to just put meat on the table to serve up for consumption. I’ve got a good list of starting topics, and so I’m excited to start getting to it.

Cheers.

Share this post:

  • email
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • Google Bookmarks
  • StumbleUpon