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.
SPFolder
is 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 an SPFolder
. Also you can't use SPWeb.GetFolder
as 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:
var path = SPUtility.GetGenericSetupPath(@"TEMPLATE\LAYOUTS\Projekt\DocumentTemplates");
This path you could now Access with regular stream readers, System.IO.File
etc.
EDIT: For SharePoint 2013 and above the mentioned method is obsolete as in newer SharePoint versions references to the _layouts
folder always contain the SharePoint version in the path (e.g. /_layouts/15
for SharePoint 2013 /_layouts/14
for SharePoint 2010.
The new method is SPUtility.GetVersionedGenericSetupPath
. The method does not exist in SharePoint 2010.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With