I wish to download a file from a sharepoint2010 site as if you were downloading a normal document from a Document Library. What functions are available in C# to call these functions?

I know you can do so by using the following link:


But i do not have a url. The file data is loaded in a Stream and i can't use anything else. If there's a way to let sharepoint download streams or if there's a work around for the missing url please let me know.

  • If you have the file in a stream, then how does this pertain to sharepoint? – Mike Jan 23 '13 at 15:19
  • It isn't. The file in the stream is received from a webservice. – user1746525 Jan 23 '13 at 15:23
  • can you explain a bit more about what you are trying to do and where you are getting your stream from? what webservice? what does this accomplish for you? – Mike Jan 23 '13 at 15:26
  • The Web Service is from a company application which manages documents on a local network. Using sharepoint the documents should also be able to available outside this network. But we do not want to actually save the documents on sharepoint. The application should still manage the files. The only way to get the files from outside the network is using the webservice. The webservice only gives me a stream with the specified file data. – user1746525 Jan 23 '13 at 15:29

somthing like this:

byte[] bytes = memoryStream.GetBuffer();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=report.pdf");


also check this out:

// Override the ProcessRequest method. 
public void ProcessRequest(HttpContext context) 
//Create and populate a memorystream with the contents of the 
//database table 
System.IO.MemoryStream mstream = GetData(); 
//Convert the memorystream to an array of bytes. 
byte[] byteArray = mstream.ToArray(); 
//Clean up the memory stream 
// Clear all content output from the buffer stream 
// Add a HTTP header to the output stream that specifies the default filename 
// for the browser's download dialog 
context.Response.AddHeader("Content-Disposition", "attachment; filename="+context.Request.Form["txtFileName"].ToString()); 
// Add a HTTP header to the output stream that contains the 
// content length(File Size). This lets the browser know how much data is being transfered 
context.Response.AddHeader("Content-Length", byteArray.Length.ToString()); 
// Set the HTTP MIME type of the output stream 
context.Response.ContentType = "application/octet-stream"; 
// Write the data out to the client. 
catch (Exception Ex) 
throw Ex; 
// Override the IsReusable property. 
public bool IsReusable 
get { return false; } 




hope it helps :)


I'm not sure if this will work in your situation but one of the things we've done in the past for a similar situation (hosted media files) is to create a SharePoint list that displays the standard file information like name, size, revision, etc, but all of that data is pulled from the external source on a schedule and the list is kept synchronized. There is a hyperlink field that links to download link on the external service so, to the end user, this appears as a file in SharePoint but the file is actually hosted remotely.

This can be kept in sync either via Timer job, a custom coded scheduled task, or, even via the Business Data Catalog if that will work for your situation.

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.