Search code examples
c#sharepointspsitespweb

Programmatically Accessing SharePoint Style Library from within C#


Firstly, I'm a newbie to C# and SharePoint, (less than a month's experience) so apologies if this is an obvious or easy question but I've been trawling the net for a couple of days now with absolutely no success.

I have an xslt file that I have stored in a subdirectory of 'Style Library' from within the new website but how can I access this from within c#?

I've looked at SPSite and SPWeb but neither seems able to do quite what I want.

Any and all help will be gratefully received.

Many thanks

c#newbie


Solution

  • Here is a bit of code to retrieve the list items from a list:

    SPList list = web.Lists["MyLibrary"];
                if (list != null)
                {
                    var results = from SPListItem listItem in list.Items
                                  select new 
                                  {
                                      xxx = (string)listItem["FieldName"]),
                                      yyy  = (string)listItem["AnotherField"],
                                      zzz = (string)listItem["Field"]
                                  };
                }
    

    To retrieve a file you could also use this method on SPWeb: GetFileAsString