Archives / 2008 / June
  • Opening and Reading an XML file in a document library

    So in a recent SharePoint implementation, I was required to allow users to create links in web parts that performed server side functions. Most of the functions were known quantities but they were almost all external systems. Most of the requirements were to just display security trimmed links to Oracle and other external systems. I had envisioned a single sign-on, BDC system but it turned out the client didn't have the infrastructure to support getting the external data in that way.

    My solution was to create an Xml file describing the kinds and order of calls for each web part and place all the Xml files in a document library for extraction and processing. That allows future users to pull the file, edit it and replace it as appropriate. I had a single web part with a custom text property set to the name of the Xml file. So the user added this generic web part to as many pages as necessary and set the property to the flavor they wanted to show on that page in that position. Pretty simple.

    So I needed to open a file in memory from a document library and operate on it as a normal Xml document. Here is the basic structure of one of the files. There are a lot more options in the structure but this gives you the idea.


    XML Document

    Easy to read and easy to parse. I'm no whiz at parsing Xml but I built a data object to wrap this structure and it seemed to perform pretty well. Here is the code I used to get the Xml file from the library into an Xml document object. This project required VS 2005 so I had no option for using Linq to get the data. Season to taste. Caveat Emptor.



    I've seen another way of doing this but this worked best for my situation. I'd be interested in any pointers from others who have a different tack.