tags:

views:

632

answers:

2

Hi!

Is there are way to progammatically determine the root directory's local path of the current sharepoint site?

Best Regard
Oliver Hanappi

+1  A: 

siteCollection.WebApplication.IisSettings[SPUrlZone.Default].Path;

Colin
+2  A: 

You can determine the physical local path of the Web Application by querying the IisSettings colelction on your site.

Such as this:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace WSStest
{
  class Program
  {
    static void Main(string[] args)
    {
      using (SPSite site = new SPSite("http://<YOURSITE>"))
      {
        string localPath = site.WebApplication.IisSettings[SPUrlZone.Default].Path.ToString();
        Console.WriteLine("Local path: " + localPath);
      }
    }
  }
}
Magnus Johansson
I only have a couple of watch-outs I'd add to Magnus' code (which is basically on-the-money). First, you're probably better off using the SPContext.Current.Site instead of explicitly opening a site (since you *are* looking for the current site). Second: don't assume SPUrlZone.Default. If you happen to be accessing via a URL for an extended zone and actually want the extended web's site (IIS) path, the correct path will not be returned with the code above. Instead, do a lookup in the AlternateUrls property of the SPWebApplication to see which zone the call is from and use it instead.
Sean McDonough