ZIP File downloaded has problems

Aug 3, 2009 at 6:11 PM

Hi,

My Application is running on a server. This is the place where the file to be archived is available.

When a download button is clicked, the file is being saved with ".zip" extension. However, when I try to extract the file using WinZip,I am getting an error as: Cannot Download the File.

It's working fine when I run it in the development system (local).

Here's the code:

                  

                    Response.Clear();
                    Response.BufferOutput = false;
                    string archiveName = "Archive_US.zip";

                    Response.ContentType = "application/zip";
                    Response.AddHeader("content-disposition", "attachment; filename=" + archiveName);
                    string Password = string.Format("reports_{0}", DateTime.Now.ToString("HHmmss"));
                    using (ZipFile zip = new ZipFile())
                    {
                        zip.Password = Password;
                        zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
                        zip.Save(ConfigurationManager.AppSettings["USPath"].ToString());
                        string fileName = string.Format(Response.OutputStream);
                    }
                    HttpContext.Current.ApplicationInstance.CompleteRequest();

I tried extracting using WinRar, here, it extracts the file as an Unknown type. I have to right click on the extracted archive file and open with Winrar , which goes to the archived file and then asks for the password.

 

Can anyone please check on this? This only happens , when the file is being downloaded from a location other than the local system.

 

Thanks

Abhijith

Coordinator
Aug 3, 2009 at 7:06 PM

I'm sorry, I don't understand the problem, at all.   Your description is not clear to me.

I think the problem is, you cannot open a zip file in WinZip. I think the zip file is being generated from an ASPNET page.    But then,  I don't understand why you get an error like "Cannot download the file".  Is the file present or not, on the local system?  Are you trying to open a file that is on a local disk?  Or...? 

If the file is not present on the local system, then can you save it?   Normally you get a "Save As..." dialog when you click on a download link in a web browser.  What happens if you select "Save"  and specify a location for the file?   Do you get "Cannot download"?    If you don't, in other words if it downloads correctly, then can you open the file on that location?

Also your description seems to have trailed off, truncated or something.  "I have to right click on the extracted archive file and open with WinRar, which goes to the arc".  I have no idea what you are talking about here.  What extracted archive file?  What is being extracted?  I thought you were having trouble opening a file.     Now you are talking about an extracted file.  ???  And what does it mean "goes to the arc". ??

please clarify.  I don't know what your app is doing, what zip tools you have, or what you are seeing.  you'll have to describe all that, if it's relevant.  

 

Aug 3, 2009 at 7:34 PM

Sorry Cheeso, I think some of the text got truncated.

Anyway Here's the problem:

I have a download link on a web app that is being hosted on a server. Now, I run the app through the browser in my local system .

There is a download button on the page. When this button is clicked, it generates a Save Dialog box, with option to "SAVE AS".

When I give the download path as my local system hard disk, it gets saved at that location as "Archive.zip". This file is being downloaded from the

server.

Now, There are two option by which I can extract this zip file. One by using, WIN ZIP and the other using WIN RAR.

1. When I try to extract using WinZip, I get the error as : "Cannot download the file".

2. When I try to extract using WinRar, the file gets extracted (doesn't ask for password here). The extracted file type is Unknown.

   I have to right click and select open with and select the file type as Win Rar to open the file. Here It shows me the File in the Win Rar

  window and when I click on the file to open it, it asks for the password.

 

I hope my explanation is clear enough now, If not, please let me know.

 

Thanks
Abhijith

 

 

 

 

Coordinator
Aug 3, 2009 at 7:47 PM

You have an option to "Save As.."  and you save the file successfully.  Is that correct?

And then you have a saved file on your local filesystem, is that correct?   What browser are you using?  How long does the download take?  and how do you confirm that the download is complete?

then, after the download is complete, when you try opening the local file, you get a message from WinZip saying "Cannot download file."  Is that correct?

If so, I don't understand what is happening. 

I don't understand how you can get a message about downloading if there is no download involved?   The download is complete., if I am understanding you correctly.   You are merely opening a file, that had previously been downloaded. 

There is something I am still not understanding about all of this.

First, how do you try to extract with WinZip?  do you click on the WinZip icon, then Click the Open icon within WinZip, and then specify the path of the newly-downloaded zip file that you want to open?  if not, then how? 

Also, can you check - After the download is complete, can you verify the size and timestamp and name of the downloaded file?  Can you give me an explorer screenshot that shows the downloaded file and all of these properties? 

 

Aug 3, 2009 at 8:04 PM

You have an option to "Save As.."  and you save the file successfully.  Is that correct?

Yes. The file is saved successfully

And then you have a saved file on your local filesystem, is that correct?   What browser are you using?  How long does the download take?  and how do you confirm that the download is complete?

I am using IE 7.0 . The download hardly takes few seconds. And the Archive.zip is visble on the location where I save it.

then, after the download is complete, when you try opening the local file, you get a message from WinZip saying "Cannot download file."  Is that correct?

Yes. When I try to extract using WinZip, I get the message.

If so, I don't understand what is happening. 

I don't understand how you can get a message about downloading if there is no download involved?   The download is complete., if I am understanding you correctly.   You are merely opening a file, that had previously been downloaded. 

 

There is something I am still not understanding about all of this.

First, how do you try to extract with WinZip?  do you click on the WinZip icon, then Click the Open icon within WinZip, and then specify the path of the newly-downloaded zip file that you want to open?  if not, then how? 

Yes, I do click on the open icon within winzip and then specify the path of the newly-downloaded file.

Also, can you check - After the download is complete, can you verify the size and timestamp and name of the downloaded file?  Can you give me an explorer screenshot that shows the downloaded file and all of these properties?

 

How Do I paste the screenshots ?? I am not able to paste them here.

 

 

 

 

Coordinator
Aug 3, 2009 at 8:29 PM

To past images, you can upload images to a free image host server, like tinypic.com, and then click the <HTML> icon in the editor window, and insert the appropriate <img> tag.

Coordinator
Aug 3, 2009 at 8:31 PM
Edited Aug 3, 2009 at 8:50 PM

Also, what is the EXACT error message from WinZip?   And are you sure it is really coming from WinZip?  can you get a screenshot of that, too?

EDIT: I searched for "cannot download the file" and "Winzip" and found no matches.  Are you sure that is the message? 

Aug 3, 2009 at 8:59 PM

Hi Cheeso,

This is the Downloaded file:

Image and video hosting by TinyPic

 

Properties :

Image and video hosting by TinyPic

 

When I extract the Archive_US.zip using WinZip, I get the following message:

Image and video hosting by TinyPic

 

 

 

 

 

When I extract the Archive_US.zip using WinRar, I get the following file:

Image and video hosting by TinyPic

 

 

 

Now, I have to do a : “Open With” and select WinRar Archiver to open the folder inside this archive.

Image and video hosting by TinyPic

 

 

 

Once I select the WinRAR archiver, I get the following window:

 

Image and video hosting by TinyPic

 

 

The USReports.csv file is password protected.

Coordinator
Aug 3, 2009 at 9:22 PM
Edited Aug 3, 2009 at 9:28 PM

ok, getting better. . .

It's clear now that you are not getting a message saying "Cannot download the file".  The message I see is "Cannot open file: it does not appear to be a valid archive."  and "if you downloaded this file, try downloading the file again." 

Just a note:  I can help you best if you are accurate in ALL of your descriptions.  If you give me a description that is inaccurate, then I cannot help you.  In addition, it's a giant waste of everyone's time.

Ok, now if WinZip cannot open the file, I suspect the zip file is corrupted.  

You then said that when you extract the same archive with WinRAR, you get a file called "Archive_US".  it appears to have no extension.  is that right?  What I understand is that you opened the Archive_US.zip file with WinRar, and extracted its contents, and got a new file, named "Archive_US".  Is that right?  If that is not right, then where did the file named "Archive_US" come from?

Then you open *that* file with WinRar.  but because it has no extension, you have to do the right-click and open-with trick.  And then WinRar succeeds in opening the file.

It sounds to me, from your description, that you have a zip file within a zip file?  And the zip file within the zip file does not have the .zip extension.  Is that right? 

Why do you use a zipfile within a zipfile?

I'm sure there is still something I don't understand about this very confusing situation.

Is it true that the first (outer) zipfile itself is 4364 bytes, and then there is a single zipfile contained within it, and then contained within that zip file is a single file of 1120 bytes?  Something is wrong with your zip file. 

in your code, what does the highlighted line do?:

     using (ZipFile zip = new ZipFile())
        {
            zip.Password = Password;
            zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
            zip.Save(ConfigurationManager.AppSettings["USPath"].ToString());
            string fileName = string.Format(Response.OutputStream);
        }
     HttpContext.Current.ApplicationInstance.CompleteRequest();

Also, look at the line you have for Save().  Your code appears to be saving the ZipFile to a path that is specified in the web.config file.  Is that correct?  Is that what you really want?  Remember that this code runs in an ASPNET page, which runs on a server.  The path specified in the web.config file is relative to the server.  if you specify c:\document\path.zip in the web config file, it will save to that location on the server.   This seems like the wrong thing to do, if you are trying to create a zipfile that gets downloaded to the browser. 

I think that odd Save() line may be the reason you have a zip file within a zip file.   This is not a normal thing to do.  It looks very broken to me.  Not only are you saving to a server-based path, but also you are saving to the exact location of the file that you are trying to add to the zip.  ???   That makes no sense to me.  Normally people would do something like this:

     using (ZipFile zip = new ZipFile())
        {
            zip.Password = Password;
            zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
            zip.Save(Response.OutputStream);
        }
     HttpContext.Current.ApplicationInstance.CompleteRequest();

In this case, ConfigurationManager.AppSettings["USPath"].ToString() is the file being added to the zip, and the zipfile gets downloaded to the requesting browser.

Aug 3, 2009 at 9:42 PM

Hi Cheeso,

Thanks for the reply. I am sorry if my questions are confusing, I am trying my best to be as transparent as possible.

Anyways, below are some of the clarifications:

 

Here is the full code :

                    Response.Clear();
Response.BufferOutput = false;
string archiveName = "Archive_US.rar";

Response.ContentType = "application/rar";
Response.AddHeader("content-disposition", "attachment; filename=" + archiveName);
string Password = string.Format("reports_{0}", DateTime.Now.ToString("HHmmss"));
using (ZipFile zip = new ZipFile())
{
zip.Password = Password;
zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
zip.Save(Response.OutputStream);
}
HttpContext.Current.ApplicationInstance.CompleteRequest();

 

You then said that when you extract the same archive with WinRAR, you get a file called "Archive_US".  it appears to have no extension.  is that right?  What I understand is that you opened the Archive_US.zip file with WinRar, and extracted its contents, and got a new file, named "Archive_US".  Is that right?  If that is not right, then where did the file named "Archive_US" come from?

Yes. The extracted file does not have any extension. and I open the zip file with WinRAR and got the Archive_US file.

 

 

 

Then you open *that* file with WinRar.  but because it has no extension, you have to do the right-click and open-with trick.  And then WinRar succeeds in opening the file.

It sounds to me, from your description, that you have a zip file within a zip file?  And the zip file within the zip file does not have the .zip extension.  Is that right? 

Yes. That is exactly what is happening.

Why do you use a zipfile within a zipfile?

I am not sure why the ZipFile inside a zip file is being created!! You can refer to the code above.

I'm sure there is still something I don't understand about this very confusing situation.

Is it true that the first (outer) zipfile itself is 4364 bytes, and then there is a single zipfile contained within it, and then contained within that zip file is a single file of 1120 bytes?  Something is wrong with your zip file. 

Yes. The size is right

in your code, what does the highlighted line do?:

     using (ZipFile zip = new ZipFile())
{
zip.Password = Password;
zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
zip.Save(ConfigurationManager.AppSettings["USPath"].ToString());
string fileName = string.Format(Response.OutputStream);
}
HttpContext.Current.ApplicationInstance.CompleteRequest();

Also, look at the line you have for Save().  Your code appears to be saving the ZipFile to a path that is specified in the web.config file.  Is that correct?  Is that what you really want?  Remember that this code runs in an ASPNET page, which runs on a server.  The path specified in the web.config file is relative to the server.  if you specify c:\document\path.zip in the web config file, it will save to that location on the server.   This seems like the wrong thing to do, if you are trying to create a zipfile that gets downloaded to the browser. 

I think that odd Save() line may be the reason you have a zip file within a zip file.   This is not a normal thing to do.  It looks very broken to me.  Not only are you saving to a server-based path, but also you are saving to the exact location of the file that you are trying to add to the zip.  ???   That makes no sense to me.  Normally people would do something like this:

     using (ZipFile zip = new ZipFile())
{
zip.Password = Password;
zip.AddFile(ConfigurationManager.AppSettings["USPath"].ToString(), "Reports");
zip.Save(Response.OutputStream);
}
HttpContext.Current.ApplicationInstance.CompleteRequest();

In this case, ConfigurationManager.AppSettings["USPath"].ToString() is the file being added to the zip, and the zipfile gets downloaded to the requesting browser.

If you refer to my complete code , it is doing the same thing that you've mentioned . But still the issue persists.

 

Thanks,

Abhijith

Coordinator
Aug 3, 2009 at 10:15 PM

Abhijith, yes, the issue persists.  That is not a surprise.  Here's why.

Your original code - posted on the first message of this thread - caused a corruption.  Did you ever run that code?   Even once?   I think you did.  If so, it explains why you have a zip file within a zip file.  As soon as you ran that code, the file that is referred to by ConfigurationManager.AppSettings["USPath"].ToString() was overwritten.  It was over-written with a ZIP file. 

Then, suppose you fixed your code.  With the fix, I suppose it does not save to ConfigurationManager.AppSettings["USPath"].ToString(), instead it saves to Response.OutputStream.  But the file you are now adding to the zip file is obtained from ConfigurationManager.AppSettings["USPath"].ToString(), which we know contains a ZIP.  We know it was overwritten before, with the broken code.  It may not have the name of a zip, but because you ran the broken code once, the original content of that file on the server is gone.  The content is replaced with a zip file, though it may not have the .zip extension.

It seems to me your code and your tests are a little out of control.  You need to do a reset, start over. Clear out the old files, clear out the old code.  Verify that your zip.Save() is saving to the proper place.  Verify that the file you are adding is what you think it is.   take it step by step.

The original problem seems to have come from bad code on your part - saving a zip over a file you were loading.  Since then, who knows what things we're trying to chase down?  Start over.

 

 

Aug 3, 2009 at 10:32 PM

Hi Cheeso,

Thanks for the help. Will sure do try to rework and get back if it's working.

Aug 6, 2009 at 11:43 PM

Hi Cheeso,

Sorry for not replying back soon enough. You were right.  I re-wrote the code ,tested it over again. It works now.

Thanks a lot for the help and extremely sorry for wasting your precious time.

 

Cheers

Abhijith

Coordinator
Aug 7, 2009 at 1:36 AM

Super, glad it's working for you.

Software can be tricky sometimes.