【问题标题】:Upload a zipfile from winform to asp.net [duplicate]将 zip 文件从 winform 上传到 asp.net [重复]
【发布时间】:2019-03-21 11:33:02
【问题描述】:

我正在寻找上传存储在本地计算机上的 zip 文件并将其上传到 asp.net 服务器

到目前为止我尝试了什么?

我尝试将压缩文件的纯文本发送到服务器,但由于压缩文件似乎发生了变化,这不起作用。

所以我想知道将 ZipFile 从 WinForm(存储在本地计算机上)发送到运行 asp.net 的服务器的最佳方式是什么

谢谢

【问题讨论】:

    标签: c# asp.net winforms


    【解决方案1】:

    上传.docx.png.pdf.zip 等文件没有区别。

    你可能已经准备好这个帖子了:

    Uploading Files in ASP.net without using the FileUpload server control

    基本上,它说:

    您可以在您的aspx 文件中使用:

    <form id="form1" runat="server" enctype="multipart/form-data">
     <input type="file" id="myFile" name="myFile" />
     <asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
    </form>
    

    在后面的代码中:

    protected void btnUploadClick(object sender, EventArgs e)
    {
        HttpPostedFile file = Request.Files["myFile"];
    
        //check file was submitted
        if (file != null && file.ContentLength > 0)
        {
            string fname = Path.GetFileName(file.FileName);
            file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
        }
    }
    

    此外,您可以为此设置一个缓冲区,例如:

    using (FileStream fs = File.Create("D:\\_Workarea\\" + fileName))
    {
        Byte[] buffer = new Byte[32 * 1024];
        int read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
        while (read > 0)
        {
            fs.Write(buffer, 0, read);
            read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
        }
    } 
    

    还是这么简单,喜欢用:

     FileInput.PostedFile.SaveAs("~/App_Data/");
    

    【讨论】:

      猜你喜欢
      • 2011-03-31
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 2012-03-07
      • 2011-09-08
      相关资源
      最近更新 更多