从 aspx 页面读取 FileStream

发布于 2025-01-06 18:32:30 字数 711 浏览 4 评论 0原文

我使用客户端 OM 从 SharePoint 2010 检索文档。我可以使用

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

This return a type ConnectStream 检索文档。然后,我将 ConnectStream 传输到 FileStream 中,如下所示:

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

这确实会将物理文件写入本地文件系统,但我希望将来避免这种情况。现在我的代码隐藏中有一个 PDF 文档的 FileStream。我还有一个 UserControl 来在 aspx 页面中显示 PDF。从 UserControl 的代码隐藏中接受文件路径,如下所示:

<userControlName>.FilePath = <url>;

有没有办法将 fs 对象链接到 UserControl 的文件路径?

如果需要更多详细信息,请告诉我,谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2025-01-13 18:32:30

如果你想传递流对象,那么你必须在 UserControl 中创建一个 Stream 类型的公共属性。

UserControl中定义属性,

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

并从UserControl的主机(.aspx或.ascx)的代码隐藏中分配流对象的引用。

UserControl1.InputStream=stream;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文