11
votes

I need to get 14 hive path using code in C#.net.

can any one tell me how can I do this?

1
Do you want the hive path or really want to access e.g. Controltemplates / Layouts?Dennis G
i dont want to access this path. i need to 14 hive layouts path programatically(physical path).Suresh Chaudhary

1 Answers

16
votes

You can access the physical path using SPUtility - the web path by looking at the SPWeb object.

Using SPUtility to get the SetupPath of Sharepoint like so:

using Microsoft.SharePoint.Utilities;
string spSetupPath = SPUtility.GetGenericSetupPath(string.Empty);
//e.g. returns "C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\14

Or you can use SPWeb's server relative URL method:

using Microsoft.Sharepoint;
string spServerURL = SPWeb.ServerRelativeUrl;

MSDN documentation SPWeb.ServerRelativeURL

Also have an overview of the Sharepoint 2010 14 hive structure.