Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dataset .I want save it as xml and zip it for user download it .
I use code below.
the xml file saves but the save dialog doesn't appear .how can I zip it and show save dialog to user
C#
 datasetKetab dsk = new datasetKetab();
Ketab ketab = (from k in jle.Ketabs where k.KetabID == ketabid select k).Single();
                    dsk.Ketab.AddKetabRow(ketab.Nam, ketab.TedadeSafhe.Value, ketab.TedadeSoal.Value, ketab.Aks);
dsk.WriteXml(@"C:\Users\moslem\Desktop\a.xml");


ok it works. inested lonic I used system.io.compression.zipfile
but I get an error:"the process cannot access file because "zip file name" the file is using by another process"
xml and zip file is created in that folder but file will not download . why?
C#
string directoryname=MapPath("path...");
                    string xmlfile = MapPath("path..." + ketab.Nam + ".xml");
                    dsk.WriteXml(xmlfile);
                    Response.ClearContent();
                    Response.ClearHeaders();
                                       Response.ContentType = "application/zip";
                    Response.AppendHeader("content-disposition", "attachment; filename=Report.zip");
                    string zipfile=MapPath("path..." + ketab.Nam+".zip");

                    ZipFile.CreateFromDirectory(directoryname, zipfile);//error is in this line
                    //File.Delete(xmlfile);
                    Response.WriteFile(zipfile);
Posted
Updated 12-Aug-14 4:02am
v3
Comments
[no name] 12-Aug-14 7:39am    
What "save dialog"? You are not going to show any dialog from your server side code to your user sitting on the client side of things.

1 solution

dt.TableName = "Declaration";
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposi

tion", "attachment; filename=Report.zip");

using(Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile())
{
zipFile.AddEntry("Report.xml", (name,stream) => dt.WriteXml(stream) );
zipFile.Save(Response.OutputStream);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900