如何将文件作为二进制流发送?

编程入门 行业动态 更新时间:2024-10-28 04:20:53
本文介绍了如何将文件作为二进制流发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们在另一个州有一个工程部门。 他们制造机器人设备。 他们希望保存我们用于在我们的网站上编程这些机器人模块的固件文件,然后通过网页将它们作为二进制流下载。 他们将读取二进制流,但我不知道他们是如何做到的。

我之前没有做过这个二进制流。 所以作为测试,我想流式传输一个简单的txt文件。 这是我到目前为止编写的代码:

使用System; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.WebControls; 使用System.IO; namespace Nop.Web { public partial class FileStreaming:System.Web.UI.Page { protected void btnSubmit_Click(object sender,EventArgs e) { using(FileStream stream = new FileStream(" C:\\Users\\BOB\\Documents\\ mysecretfile.txt",FileMode.Create) )) { using(BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(" hello"); //writer.Write(); writer.Close(); } } lblFinished.Visible = true; } } }

因此,当我运行此网页并单击"提交"时,我会在MyDocuments中创建一个新文件。 它名为mysecretfile.txt。 但它只有Hello。 如何发送实际文件流?

解决方案

这似乎是一个Webtech问题。最好在ASP.Net论坛上询问那些人:

forums.asp/

但我至少可以给你一些提示,在这种情况下从哪里开始。您可能正在寻找的是 HTTPFileHandler 。

We have an engineering division in another state. They build robotics equipment. They want to save the firmware files we use to program these robotic modules on our web site and then download them as a binary stream via a web page. They will read the binary stream but I don't know much about how they do this.

I have not done this binary streaming before. So as a test, I want to stream a simple txt file. Here is the code I wrote so far:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; namespace Nop.Web { public partial class FileStreaming : System.Web.UI.Page { protected void btnSubmit_Click(object sender, EventArgs e) { using (FileStream stream = new FileStream("C:\\Users\\Bob\\Documents\\mysecretfile.txt", FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write("hello"); //writer.Write(); writer.Close(); } } lblFinished.Visible = true; } } }

So when I run this web page and click Submit, I get a new file created in MyDocuments. It is named mysecretfile.txt. But it only has Hello in it. How do I send the actual filestream?

解决方案

This seems a Webtech question. Better to ask those on the ASP.Net Forum:

forums.asp/

But I can at least give you some hints where to start in this case. What you might be looking for is the HTTPFileHandler.

更多推荐

如何将文件作为二进制流发送?

本文发布于:2023-11-03 07:57:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!