Access _layouts files programmaticaly (file not found exception)
-
Wednesday, September 30, 2009 4:04 PMHi everyone,
i'm developping my first WCM site with MOSS 2007.
Some pages need to access some external xml files.
To do so, I used a provisioning feature to put these files into the "_layouts" folder.
But, when i try to access them from C# code, i always get a File not Found exception
using System;
using Microsoft.SharePoint;
namespace AccesFiles
{
class FileAccess
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://myserver:1000"))
{
using (SPWeb web = site.RootWeb)
{
SPFolder folder = web.GetFolder("_layouts"); //I already tried SPFolder folder = web.GetFolder("/_layouts"); but didn't work either
SPFile file = web.GetFile("_layouts/myfile.xml");
file.MoveTo("/_catalogs");
}
}
}
}
}
Can someone tell me where i'm wrong
Thank you very much
Tryste- Edited by Mike Walsh FIN Wednesday, September 30, 2009 4:51 PM Problem : removed from Title, We know it's a problem as you posted here ...
All Replies
-
Wednesday, September 30, 2009 4:13 PM
_layouts is a virtual directory in IIS, its not a folder in SharePoint. I would provision your XML files to a document library using a feature. The feature contains a module. Here's an article which should help, "How to provision a file" http://msdn.microsoft.com/en-us/library/ms441170.aspx
My SharePoint Blog - http://www.davehunter.co.uk/blog- Marked As Answer by Trystesire Thursday, October 01, 2009 12:18 PM
-
Thursday, October 01, 2009 12:20 PMMy problem is solved if i do it that way
Thank you!

