views:

1897

answers:

5

Is there any way to get the directory path of the 12 Hive programmatically? I am creating a feature which delivers a file to the XML directory in the 12 hive, and I don't want to hardcode the directory path in my code.

Is there any Object Model property which exposes the 12 Hive directory path string as a property?

+1  A: 

Have you ever seen a SharePoint installation where the 12-hive was not in the same place as usual? I don't think Microsoft even supports having it somewhere else..

Even so you can probably do a MapPath to the "/_layouts" directory to get the value.

ArjanP
The 12-hive path can change depending on whether you have installed SharePoint on a 32bit or 64bit platform. Also, you may not have installed your server with a C:\ drive as root.
Moo
The installation path also depends on the OS language.
Flo
A: 

32bit vs. 64bit shouldn't matter because in either case Program Files is c:\Program Files.

What does matter is OS language which can change the literal text of c:\Program Files\Common Files. The right way to get that directory is: System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);

Then you can use that folder and then concatenate the rest of the items...I don't think those items are language specific.

Mark Mascolino
+8  A: 

You can use the Microsoft.SharePoint.Utilities.SPUtility.GetGenericSetupPath() method. See for more information the WSS SDK: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getgenericsetuppath.aspx

Waldek Mastykarz - MOSS MVP
That is the correct answer Waldek! If you for some reason want to get a subfolder, like features, use SPUtility.GetGenericSetupPath(@"TEMPLATE\FEATURES")
Johan Leino
+2  A: 

Why would you need to put xml files in the 12 hive? That way you are working "unsupported" Wouldn't it be easier to just deploy to the TEMPLATE\XML folder?

Colin
I agree. Use a tool like STSDEV or Visual Studio 2008 Extensions for WSS v1.3. It will help you build a solution package (wsp) and your feature and will lay down your files in the appropriate location in the 12 hive.No deployment code is necessary with this approach.
Kirk Liemohn
Or WSPBuilder, which i use mostly.
Colin
A: 

Just want to add that if you use MapPath() in Sharepoint, you receive a path that points to the location of the website, by default 'Inetpub', such as:

C:\Inetpub\wwwroot\wss\VirtualDirectories\12345\myFolder

The path doesn't point to the 12-hive.

Matth