Home
Manage Your Code
Snippet: Reading an SPFile in Sharepoint Document Library (similar for list) (C#)
Title: Reading an SPFile in Sharepoint Document Library (similar for list) Language: C#
Description: Original credit to http://www.myrocode.com/post/2009/03/05/SharePoint-2007-Read-content-from-SPFile.aspx Views: 3981
Author: Neil Richards Date Added: 11/5/2009
Copy Code  
1string content = string.Empty;
2using (SPSite oSite = new SPSite("http://localhost/"))
3{
4    using (SPWeb oWeb = oSite.OpenWeb())
5    {
6        SPDocumentLibrary doclib = (SPDocumentLibrary)oWeb.GetList(DocLibUrl);
7        SPFile htmlFile = doclib.Items[0].File;
8        using (System.IO.StreamReader reader = new System.IO.StreamReader(htmlFile.OpenBinaryStream()))
9        {
10            content = reader.ReadToEnd();
11        }
12    }
13}