Solved

How to receive a ZIP file in Asp.Net page

Posted on 2009-06-27
3
414 Views
Last Modified: 2012-06-27
Hi,

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.

Cheers
0
Comment
Question by:Asparona
3 Comments
 
LVL 21

Accepted Solution

by:
Tapan Pattanaik earned 250 total points
ID: 24727339

Upload to Database ... Dowload by Zip File:

http://www.codeproject.com/KB/aspnet/upsanddowns.aspx

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

http://msdn.microsoft.com/hi-in/magazine/cc164129(en-us).aspx

0
 
LVL 22

Assisted Solution

by:Snarf0001
Snarf0001 earned 250 total points
ID: 24727739
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
        file.SaveAs(System.IO.Path.GetFileName(file.FileName));

        //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.
0
 

Author Closing Comment

by:Asparona
ID: 31597274
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.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question