Sign up ×

Where should I store information/metadata used for configuration on every document library in a SPWeb, and how can I let site administrators change this data (as settings, GUI)?

My use case:
When a word document is added to a document library it will be converted to PDF which is copied to a another given document library.
For example any word document added to "MyArticles" will get a corresponding PDF in "MyPDFs".
The setting I need to store is an URL or some pointer stating that "MyArticles" corresponds with "MyPDFs".

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Seeing you need to store the information per Document Library, the place which makes most sense is a PropertyBag for the Document Library. Seeing the SPList/SPDocumentLibrary object doesn't have a property bag, you can use the RootFolder instead.

SPList list = web.Lists.TryGetList("MyArticles");
if(list != null)
     // GET
     string pdfLocation = list.RootFolder.GetProperty("PDFLocation");

     // SET
     list.RootFolder.SetProperty("PDFLocation", "MyPDFs");

You will need to build a custom UI for site administrators to set the location if you store it within the property bag. I assume you have custom code in an event receiver to start the conversion process.

share|improve this answer
Awesome. My own plan was to use the property bag of SPWeb, but this solution is much more clean. And thanks for noting I must make my own GUI for setting. I think some dropdown in the ribbon, perhaps using JS and COM should do the trick :) –  eirikb Sep 26 '12 at 10:30
(Not stated in my question) I'm current using JavaScript and the Client Object Model, but I can't reach the Root folder property bag, ref ECMA script - retrieving SPList property bag. Instead I'm using web.get_allProperties with get_itemand set_item –  eirikb Sep 27 '12 at 11:37

public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); //Verify the document added is a Word Document // before starting the conversion. if(properties.ListItem.Name.Contains(".Docx") || properties.ListItem.Name.Contains("Doc")) { //Variables used by the sample code. ConversionJobSettings jobSettings; ConversionJob pdfConversion; string wordFile; string pdfFile;

           //Initialize the conversion settings. 
           jobSettings = new ConversionJobSettings();
           jobSettings.OutputFormat = SaveFormat.PDF;

           //Create the conversion job using the settings. 
           pdfConversion = new ConversionJob("Word Automation Services", jobSettings);

           //Set the credentials to use when running the conversion job. 
           pdfConversion.UserToken = properties.Web.CurrentUser.UserToken;

           //Set the file names to use for the source Word document 
           //  and the destination PDF document. 
           wordFile = properties.WebUrl + "/" + properties.ListItem.Url;

           if (properties.ListItem.Name.Contains("docx"))
               pdfFile = wordFile.Replace(".docx",".pdf");
               pdfFile = wordFile.Replace(".doc", ".pdf");

           //Add the file conversion to the Conversion Job.

           //Add the Conversion Job to the Word Automation Services  
           //  conversion job queue. 
           //The conversion will not take place immeditately but 
           //  will be processed during the next run of the  
           //  Document Conversion job. 
share|improve this answer
Thanks for the answer, but I don't think this actually answers my question –  eirikb Sep 26 '12 at 10:28

Your Answer


