In another question, I finally found a way to deploy the XML file to be read via a Feature, to the _layouts folder:

Feature Elements File

Should I be deploying it there at all? I wasn't able to deploy it to my custom Feature folder which was the original plan. Should I be using the _wpresources folder instead?

_layouts is a virtual directory which maps to LAYOUTS? After deployment I was unable to find the file path in code. Where should I deploy the XML file and what is the C# syntax to grab that path?

 string path = Page.Server.MapPath("/_layouts/links.xml");

This code leads to the following error:

Could not find file 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\template\layouts\links.xml'

I want to be able to read the links.xml file which is in the virtual "_layouts" directory (currently).

  • Why don't you read the file over the network instead of from the file system on the server? You could also consider writing custom values to the web.config instead. Oct 9, 2012 at 21:59
  • Re the network, I want the whole thing to be self-contained in a Feature. XML file is a little big and convoluted to stuff into the Web.Config. I just need somewhere to deploy it to and read from it in the Web Part and my knowledge of the virtual paths is limited. Oct 9, 2012 at 22:20
  • 1
    Why can't you leave it in layouts and use HttpWebRequest to read it in to a stream for your XmlReader constructor? Oct 10, 2012 at 3:04
  • Interesting idea... could you post an answer and give me the syntax for finding the path to the file? Oct 10, 2012 at 3:38

1 Answer 1


As almost always with SharePoint the answer is it depends.

My criteria would be:

  1. Should end-user be able to change the file?
  2. If not how many features should use this file?

Depending ot the answers to the questions above pick the appropiate section below

End-users should be able to change the file
Put the file into a document library at the appropiate scope using a <Module> in a feature

File should only be used by a single feature
Put the file into the feature directory (by marking it as a element file, but not use it in any elements.xml (see below)) and use SPUtility.GetGenericSetupPath to expand the path to full path

File cand be used by multiple features
Put the file into a sub directory of LAYOUTS (using a Mapped folder) and use SPUtility.GetGenericSetupPath to expand the path to full path

How to get file into feature folder
If the file is only used by single web part put it into the Web Part SharePoint Project Item and set Deployment Type to ElementFile like this: enter image description here

If it's used by multiple entries in the feature I prefer to create an Empty Element SharePoint Project Item, add the file in there and set deployment type

  • What exactly do you mean by "by marking it as a element file, but not use it in any elements.xml"? BTW, the user will not interact in any way with this - only the Web Part which the user cannot alter. Oct 10, 2012 at 8:14
  • Description added to answer Oct 10, 2012 at 8:28
  • 1
    Thanks for the listing of alternatives. It is so nice to hear the comments after the classical "It depends". I appreciate your comments, Per! Oct 10, 2012 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.