I'm currently working on a project where I'm adding docx-files to the Layout folder in Visual Studio and then use those ducment files to create Content Types.
The problem is that I can't get the document files programmatically. Using the web browser I can get the files but not using web.GetFolder();. The code is running in a Feature Receiver when a feature is activated.
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
SPFolder docTempFolder = web.GetFolder("_LAYOUTS/Projekt/DocumentTemplates");
This code give me a collection with zero files.
What am I doing wrong?
Thanks for helping.
SPFolderis for getting objects from SharePoint document libraries/lists. You can't access files in your file system (the 14 hive) by trying to cast them as anSPFolder. Also you can't useSPWeb.GetFolderas the files are nowhere near your web. They are on your harddisk.You could get the 14 hive by using
GetGenericSetupPath, so something like this would work:This path you could now Access with regular stream readers,
System.IO.Fileetc.EDIT: For SharePoint 2013 and above the mentioned method is obsolete as in newer SharePoint versions references to the
_layoutsfolder always contain the SharePoint version in the path (e.g./_layouts/15for SharePoint 2013/_layouts/14for SharePoint 2010.The new method is
SPUtility.GetVersionedGenericSetupPath. The method does not exist in SharePoint 2010.