Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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......?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

http://msdn.microsoft.com/en-us/library/ms476063.aspx

Use this method to read the data to a stream:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.openbinarystream.aspx

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.

share|improve this answer
    
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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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