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

I have an visual webpart and I need to populate drop down with content extracted from xml file. How can I provision that XML file with feature and then how can I access it from my codebehind to be able read it?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

To deploy your file so that SharePoint can access it, you have several options but in your case as it is needed only by your feature event receiver you can deploy it under the feature's root folder. To do so, simply put your file inside a module with a deployment type of "ElementFile". Something like:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="Xmlfile" Path="Xmlfile">
        <File Path="groups.xml" Url="Xmlfile/MyFile.xml" />
    </Module>
</Elements>

Then to access it in code behind read it from the path :

properties.Definition.RootDirectory + @"\Xmlfile\MyFile.xml"
share|improve this answer

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.