问题
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:
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
回答2:
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?
回答3:
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.
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/943933/get-directory-path-to-12-hive-programmatically