Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19609 |

    I’m starting to move away from SharpZipLib and trying to get things over to Xceed, mainly because the project I am working on requires regular updating of zip files. This being a performance problem with Sharp Zip only being able to recreate the entire zip.

    My problem seems to be in waiting for the zip file to get closed. For example I write or create the zip file and once that process is finished I then read an image from the zip file. It is at this point when I get an IO error as the zipfile is still held open.

    If I wait a second or two the zipfile does get closed and a retry of the read will then succeed.

    I’ve used the filemon tool by sysinternals to confirm this and I can see that with no further program interaction, simply waiting a second or two will see the file close.

    Is there any way of finding out if the file is still open and being processed or should I just use some error checking to circumvent this issue?

    During the create/write process I have used a BeginUpdate() and EndUpdate() with all the additions happening in between. So my thinking was that when EndUpdate() is called it returns when the process is finished and the file is closed – is this not so?

    Imported from legacy forums. Posted by bill (had 4076 views)

    User (Old forums)
    Member
    Post count: 23064

    This is not the behavior that we get here. You can send a request to support, with more details on how you do things or a sample application that reproduces the problem, so we can investigate the issue further.

    Imported from legacy forums. Posted by André (had 381 views)

    User (Old forums)
    Member
    Post count: 23064

    Here’s the code I use to write my xml to a zip.

    I’m kinda new to c#, so if it’s something I’m being a complete doofus over I can only appologise in advance 🙂
    <pre>
    private void WriteXMLtoZip(string file) {
    try {
    xmlBindingSource.EndEdit();
    if (File.Exists(file)) {
    // Use the progress bar to show what’s happening
    this.toolStripProgressBar1.Value = 0;
    this.toolStripProgressBar1.Visible = true;
    this.toolStripProgressBar1.Maximum = 3;
    this.toolStripStatusLabel1.Text = “Writing XML to ZIP”;
    // Write the XML into the zip file as a stream
    ZipArchive zip = new ZipArchive(new DiskFile(file));
    this.toolStripProgressBar1.Value = 1;
    System.Windows.Forms.Application.DoEvents();
    AbstractFile zf = zip.GetFile(“data.xml”);
    if (zf.Exists) {
    zf.Delete();
    }
    this.toolStripProgressBar1.Value = 2;
    System.Windows.Forms.Application.DoEvents();
    zf.Create(); // Create data.xml if it doesn’t exist
    Stream zs = zf.OpenWrite(true);
    this.data1.WriteXml(zs);
    zs.Close();
    this.toolStripProgressBar1.Value = 3;
    System.Windows.Forms.Application.DoEvents();
    }
    } catch (Exception e) {
    MessageBox.Show(e.Message, “Error Writing XML”, MessageBoxButtons.OK, MessageBoxIcon.Error);
    } finally {
    this.toolStripProgressBar1.Visible = false;
    this.toolStripStatusLabel1.Text = currentPath;
    }
    }
    </pre>

    Imported from legacy forums. Posted by bill (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    I suggest that you enclose your zs stream within a using statement, so that it gets disposed of when you are finished using it. This may resolve the issue.

    Imported from legacy forums. Posted by André (had 399 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your feedback. It is appreciated.

    I’ll certainly work on the “using” approach – but as I said I’m new to this c# stuff and found myself holding the file open in another area, not related to Xceed zip. So It appears Xceed zip does exactly as it should and does in fact tidy up after itself. It’s just me that doesn’t 🙂

    I was reading the first two bytes of the file to ensure the requested file is actually a zip file before passing it to Xceed zip. In doing so I missed closing that stream. Completely my error.

    Thanks again.

    Imported from legacy forums. Posted by bill (had 4682 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.