locked
export to zip RRS feed

  • Question

  • User-1795972349 posted

    here i add the refence sir 

    and all pdf genrate in image(floder)

    how export to zip

    error show in below

    sir?

    using ICSharpCode.SharpZipLib.Zip;

    protected void Button2_Click(object sender, EventArgs e)
    {

    DataTable dt = new DataTable();
    dt = obj.pdfall();
    int count = dt.Rows.Count;
    for (int i = 0; i < count; i++)
    {
    StringBuilder htmlText = new StringBuilder();
    StringWriter sw = new StringWriter(htmlText);
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    foreach (DataRow dr in dt.Rows)
    {

    string now = System.IO.File.ReadAllText(Server.MapPath("hello.html"));
    string id = dt.Rows[i]["id"].ToString();
    now = now.Replace("#",dt.Rows[i]["FirstName"].ToString());
    now = now.Replace("*", dt.Rows[i]["Email"].ToString());
    now = now.Replace("$",dt.Rows[i]["Country"].ToString());
    htmlText.Append(now);

    Bindgrid(id);
    GridView1.RenderControl(hw);
    break;
    }

    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    // PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    string PDFName = String.Format("\\{0}_ProjectDetail.pdf", i);
    //dt.Rows[i]["FirstName"].ToString()
    string path = Server.MapPath("image");
    PdfWriter.GetInstance(pdfDoc, new FileStream(path + PDFName, FileMode.Create));

    pdfDoc.Open();

    htmlparser.Parse(sr);

    pdfDoc.Close();


    Response.Write(pdfDoc);
    Response.Clear();
    }

    CreateZIP();

    }

    public void CreateZIP()
    {

    Response.ContentType = "application/zip";
    Response.Clear();
    Response.AppendHeader("content-disposition", "attachment;filename=DownloadRecordings.zip");
    // Code to Zip a Folder.

    string sPath =Server.MapPath("image");

    ZipOutputStream zipOut = new ZipOutputStream(Response.OutputStream);

    foreach (string fName in Directory.GetFiles(sPath))
    {
    FileInfo fi = new FileInfo(fName);
    ZipEntry entry = new ZipEntry(fi.Name);
    FileStream sReader = File.OpenRead(fName);
    byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
    sReader.Read(buff, 0, (int)sReader.Length);
    entry.DateTime = fi.LastWriteTime;
    entry.Size = sReader.Length;
    sReader.Close();
    zipOut.PutNextEntry(entry):                                                                            error;Specified method is not supported.
     zipOut.Write(buff, 0, buff.Length);
    }

    zipOut.Finish();
    zipOut.Close();

    Response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();
    }

    Wednesday, June 18, 2014 3:01 AM

All replies

  • User724169276 posted

    Whats the point of creating duplicate new threads again and again.Stick to one.You will get better suggestions.

    Wednesday, June 18, 2014 3:06 AM
  • User-1795972349 posted

    here i genrate pdf file for all user 

    i have 30 user so 30 pdf store in image(floder)

    now how i show zip file 

    zip(30 user pdf file)

    Wednesday, June 18, 2014 3:14 AM
  • User724169276 posted

    I already told you to separate the logic.The codes i shared in your previous post is to zip the contents of a folder and let the end user download them.So first dump some pdf files in your source location and try the codes.

    Wednesday, June 18, 2014 3:21 AM
  • User-1795972349 posted

    now i create new floder zip it have some pdf file

    this not export to zip

    it show same error:Specified method is not supported.

    how clear the error

    sir!

    protected void Button2_Click(object sender, EventArgs e)
    {

    CreateZIP();

    }

    public void CreateZIP()
    {

    Response.ContentType = "application/zip";
    Response.Clear();
    Response.AppendHeader("content-disposition", "attachment;filename=DownloadRecordings.zip");
    // Code to Zip a Folder.

    string sPath =Server.MapPath("zip");

    ZipOutputStream zipOut = new ZipOutputStream(Response.OutputStream);

    foreach (string fName in Directory.GetFiles(sPath))
    {
    FileInfo fi = new FileInfo(fName);
    ZipEntry entry = new ZipEntry(fi.Name);
    FileStream sReader = File.OpenRead(fName);
    byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
    sReader.Read(buff, 0, (int)sReader.Length);
    entry.DateTime = fi.LastWriteTime;
    entry.Size = sReader.Length;
    sReader.Close();
    zipOut.PutNextEntry(entry);                                                                  Error:Specified method is not supported.
    zipOut.Write(buff, 0, buff.Length);
    }

    zipOut.Finish();
    zipOut.Close();

    Response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();
    }

    Wednesday, June 18, 2014 3:34 AM
  • User724169276 posted

    If you have a folder named zip in your solution , then use below line instead of yours:

    string sPath = Server.MapPath("~\zip\");

    Wednesday, June 18, 2014 3:40 AM
  • User-1795972349 posted
    string sPath = Server.MapPath("~\zip\");              errors

    Error 1 Newline in constant 

    Error 2 Unrecognized escape sequence

    Wednesday, June 18, 2014 3:43 AM
  • User724169276 posted
    string sPath = Server.MapPath(@"~\zip\");

    OR

    string sPath = Server.MapPath("~\\zip\\");
    Wednesday, June 18, 2014 3:45 AM
  • User-1795972349 posted

    it show same previews error

    error:Specified method is not supported.

    Wednesday, June 18, 2014 3:49 AM
  • User724169276 posted

    Specified method is not supported.

    use below namespaces also:

    using System.IO;
    using ICSharpCode.SharpZipLib.Core;

    Wednesday, June 18, 2014 3:52 AM
  • User-1795972349 posted
    using ICSharpCode.SharpZipLib.Core;              error

    Error 1 The type or namespace name 'Core' does not exist in the namespace 

    Wednesday, June 18, 2014 4:50 AM