How to receive a ZIP file in Asp.Net page


I need to create a web site or page that will receive a Zip file sent to it via http. When I get the zip I'm going to open the file, do things with the contents and email them to some where else.

I'm used to dealing with zip files in a WinForm so I should be ok once I have the file.

Its been almost two years since I played with http and ASP.Net. I need to get my feet under me again and right now I'm drawing a HUGE blank. Can some one please get me started?

How can I tell when a zip file has been sent to the page? I assume every time someone hits my site or a particular page then the page_load event will fire for that page.

So I suppose I need a method to examine the http to look for a zip file every time the page_load fires?

Any help to get me going would be really appreciated.

Who is Participating?
Tapan PattanaikConnect With a Mentor Senior EngineerCommented:

Upload to Database ... Dowload by Zip File:

Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#:

Snarf0001Connect With a Mentor Commented:
You're correct about the page_load, and you need to be checking the Request.Files collection.  Assuming you're comfortable with the zip file as you say, then i'll leave it at either you can save the file to disk and do what you need to, or just read it into memory.

protected void Page_Load(object sender, EventArgs e)
    foreach(HttpPostedFile file in Request.Files)
        //this would save the file to disk

        //with the file.InputStream, you could read into memory and manipulate that way

Note 2 things, if you're going to have other functionality on that page (which i would assume you won't...), then wrap the foreach loop in a

if (!Page.IsPostBack)

for performance.
Also, be aware that the Request.Files will ONLY have files uploaded with "POST" and multipart form, NOT with the PUT method.
AsparonaAuthor Commented:
Thanks guys, this should be enough to get me going again. Its funny how fast I forget this stuff if I 'm not using the technology regularly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.