Solved

How to receive a ZIP file in Asp.Net page

Posted on 2009-06-27
3
411 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now