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 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:

http://spsite/_layouts/download.aspx?SourceUrl=UrlLocation

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.

share|improve this question
    
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
add comment

2 Answers 2

up vote 1 down vote accepted

somthing like this:

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

http://stackoverflow.com/questions/2239623/download-file-from-webservice-in-asp-net-site

also check this out:

// Override the ProcessRequest method. 
public void ProcessRequest(HttpContext context) 
{ 
try 
{ 
//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 
mstream.Flush(); 
mstream.Close(); 
// Clear all content output from the buffer stream 
context.Response.Clear(); 
// 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. 
context.Response.BinaryWrite(byteArray); 
} 
catch (Exception Ex) 
{ 
throw Ex; 
} 
} 
// Override the IsReusable property. 
public bool IsReusable 
{ 
get { return false; } 
} 
} 
} 

http://www.c-sharpcorner.com/UploadFile/jhblankenship/DownloadingFromMemStream11262005060834AM/DownloadingFromMemStream.aspx

and

http://forums.asp.net/t/1274439.aspx/1

hope it helps :)

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.