rross
rross

Reputation: 2276

Reading a FileStream from an aspx page

I retrieving a document from SharePoint 2010 using the Client OM. I'm able to retrieve the document using

var spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(<SPContext>, <documentPath>);

This return a type ConnectStream. I'm then transferring the ConnectStream into a FileStream like so:

using (var fs = new FileStream(<documentName> + ".pdf", FileMode.OpenOrCreate))
  {
       spFileInfo.Stream.CopyTo(fs);
  }

This does write a physical file to the local file system, but I'm hoping to avoid this in the future. Now I have a FileStream of a PDF document in my codebehind. I also have a UserControl to display PDF in the aspx page. From the codebehind the UserControl accepts the file path like so:

<userControlName>.FilePath = <url>;

Is there a way to link the fs object to the file path for the UserControl?

Please let me know if more detail is needed,Thanks.

Upvotes: 0

Views: 913

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94643

If you want to pass stream object then you have to create a public property of Stream type in UserControl.

Define the property in UserControl,

public System.IO.Stream InputStream {get;set;}

and assign the reference of stream object from within the code-behind of host (.aspx or .ascx) of UserControl.

UserControl1.InputStream=stream;

Upvotes: 2

Related Questions