Link to create a zip file.

bknoll22
bknoll22 used Ask the Experts™
on
What I am trying to do is create a link on our web page that will automatically create a zip file.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
So I think I figured out the part to create the zip file. I created a batch file that does that. However when I put the link on the page as follows:

<a href="test.bat">Zip Files<a>

When I click on the link it just shows the bat file in text.
David RobitailleAnalyst Programmer

Commented:
are the files on the server or on the client's computer?
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
Right now I am testing it out on my local computer with all the files needed locally. Eventually it will be on the server but again all the files needed will also be on the server.
David RobitailleAnalyst Programmer

Commented:
you cannot use this bat file this way to create the zip file. if you manage, somehow, to run the script from that link, it will be run on the client`s computer.
thats why you should create the file the way i point you. If you what to stick with the bat file, then we need to find a way to execute the bache file on the server.
here how to send the file when it`s created
http://aspalliance.com/259

Author

Commented:
Could I use an .exe program to do the zipping and then move the zip file onto their local computer? this whole application will only be used in our intranet.
David RobitailleAnalyst Programmer

Commented:
to "move the zip file onto their local computer" they need to be "downloaded" by the client,  he have to select a folder to save downloaded the file.

Author

Commented:
Ok I was confused as to how the process went for what I was trying to do but I get what you're saying now. However, I am having an issue with .Net now. It is saying that there is no such thing as System.IO.Packaging even though I am using the latest version of .Net so I'm looking into that right now. So would I be able to have a link that would run an executable or something that would create the zip file on the server than another link that points to the location of the zip file so the user would be able to save it on to their local computer. I'm sorry for all these probably simple questions but I'm not very experienced in web development and thank you for your patience.
David RobitailleAnalyst Programmer

Commented:
form the article :
  • "First, you'll need to find WindowsBase.dll so you can add a reference to it. If it's not on your .NET references, you'll probably find it in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll."
did you add the reference in your project?
Also, instead of "System.IO.Packaging" you could also try this
http://www.codeplex.com/DotNetZip

Author

Commented:
yeah I found the reference yesterday and I looked into the DotNetZip and am going to use that. I have a test case working that I will most likely use. The only concern is that firefox doesn't know how to run the .exe file that will create the zip so we will have to use IE. Not a big deal but I figured I would see if you knew of a solution.
David RobitailleAnalyst Programmer

Commented:
"The only concern is that firefox doesn't know how to run the .exe file that will create the zip"
Hu??? you are running EXE on a Client`s machine??? That raise some serious security issues, but that a different matter.
Anyway, What i<m trying to tell you from the bigening is to run the zip creation precess on the server, so it wont be browser dependant.
ex you create a link button that create the zipfile ant then forward the file client via response.write or response.binarywrite dependig on how you created the file.
 

Author

Commented:
The zip creation process is what I dont understand and we might be saying the same thing but this is the scenario I want:

The User on the client machine clicks the link which creates the zip file on the server.

I understand how the user gets the file from the server its the user starting the zip creation process I dont know how to do.
David RobitailleAnalyst Programmer

Commented:
ok, here some exemple:
this one clicking on the ok button will do it:
http://cheeso.members.winisp.net/DotNetZipHelp/Example-ASPNET.htm
this one is the same, but simplified (without all the stuff around)
http://blogs.msdn.com/dotnetinterop/archive/2008/06/04/dotnetzip-now-can-save-directly-to-asp-net-response-outputstream.aspx
 

Author

Commented:
Ok so here is a test page that I made however it asks if the client wants to save Default.aspx not the zip file.

<%@ Page
    Language="C#"
    Debug="true" %>
   
   
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Ionic.Zip" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script language="C#" runat="server">
   
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "Application/zip";
        string filePath = @"C:/TestSite/test.txt";

        using (ZipFile zip = new ZipFile())
        {
            zip.AddFile(filePath);
            zip.Save(Response.OutputStream);
        }
        Response.End();
    }
   
    public String width = "100%";
   
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
Analyst Programmer
Commented:
this is because you did not put the filename, add this after the " Response.ContentType" line
 Response.AddHeader("content-disposition", "filename=test.zip");

I also notice that you put this in the pahe load event, you could put this in a linkbuton click event so you will not need a second page.
also, add a "Response.Clear();" before the Response.ContentType line

Author

Commented:
yeah I was just doing it in the page load event because I was testing. I think I finally got it to work Thank you very much.
David RobitailleAnalyst Programmer

Commented:
i`m glad i could help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial