0

I am looking to upload a zipfile stored on a local computer and upload it to an asp.net server

What have I tried so far?

I have tried sending the plain text of the zipfile to the server but that doesn't work due to the zipfile seeming to change.

So what I want to know is what is the best way of sending a ZipFile from a WinForm (Stored on a local computer) to a server running asp.net

Thank you

1 Answers1

0

There is not difference between upload a file like .docx, .png, .pdf or .zip file.

You might ready this thread:

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

Basically, it says:

You can use in your aspx file:

<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>

In code behind :

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)));
    }
}

Also, you can us a buffer for that, like:

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);
    }
} 

Or so simple, like to use:

 FileInput.PostedFile.SaveAs("~/App_Data/");
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157