Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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).

share|improve this question
    
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. –  RJ Cuthbertson Oct 9 '12 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. –  IrishChieftain Oct 9 '12 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? –  RJ Cuthbertson Oct 10 '12 at 3:04
    
Interesting idea... could you post an answer and give me the syntax for finding the path to the file? –  IrishChieftain Oct 10 '12 at 3:38

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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. –  IrishChieftain Oct 10 '12 at 8:14
    
Description added to answer –  Per Jakobsen Oct 10 '12 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! –  Anatoly Mironov Oct 10 '12 at 9:46
    
That worked Per, thanks very much! :-) –  IrishChieftain Oct 10 '12 at 15:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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