i want to retrieve the files from sharepoint document libraries url to filestream using aspx and c# coding.

Can any help me how to do it......?


Use this method to get a File object from a URL:


Use this method to read the data to a stream:


If you want to go through all files in a document library, you'll need to write a method that opens an SPList instance of your library, then gets a collection of listitems (SPListItemCollection) from that list, and access the SPListItem.File object of each item.

  • I used SPFile to downlaod the file. Its downloaded. When i tried to open, it is saying that "File is Corrupted"....? Can you have an idea Why it is happening..? – user2587 Mar 11 '11 at 7:14

I ran into this old question, but maybe this will help someone:

Microsoft.SharePoint.SPFile spFile = Microsoft.SharePoint.SPContext.Current.Web.GetFile( "subcat/test.docx" );

This will get the local file automatically for you, doing most of the work.

  • While this post may answer the question, we prefer more details such as "why". Please edit your post with additional details. See answer for general guidelines. – SPDoctor May 7 '12 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.