如何将文件作为二进制流发送? [英] How to send a file as a binary stream?

查看:104
本文介绍了如何将文件作为二进制流发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


我之前没有做过这个二进制流。  所以作为测试,我想流式传输一个简单的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论坛上询问那些人:


http://forums.asp.net/


但我至少可以给你一些提示,在这种情况下从哪里开始。您可能正在寻找的是
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:

http://forums.asp.net/

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


这篇关于如何将文件作为二进制流发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆