Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 80119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:15:09+00:00 2026-05-10T21:15:09+00:00

I am using the SharpZipLib open source .net library from www.icsharpcode.net My goal is

  • 0

I am using the SharpZipLib open source .net library from http://www.icsharpcode.net

My goal is to unzip an xml file and read it into a dataset. However I get the following error reading the file into a dataset: ‘Data at the root level is invalid. Line 1, position 1.’ I believe what is happening is the unzipping code is not releasing the file for the following reasons.

1.) If I unzip the file and exit the application. When I restart the app I CAN read the unzipped file into a dataset. 2.) If I read in the xml file right after writing it out (no zipping) then it works fine.
3.) If I write the dataset to xml, zip it up, unzip it, then attempt to read it back in I get the exception.

The code below is pretty straight forward. UnZipFile will return the name of the file just unzipped. Right below this call is the call to read it into a dataset. The variable fileToRead is the full path to the newly unzipped xml file.

string fileToRead = UnZipFile(filepath, DOViewerUploadStoreArea); ds.ReadXml(fileToRead )  private string UnZipFile(string file, string dirToUnzipTo) {         string unzippedfile = '';          try         {             ZipInputStream s = new ZipInputStream(File.OpenRead(file));             ZipEntry myEntry;             string tmpEntry = String.Empty;             while ((myEntry = s.GetNextEntry()) != null)             {                 string directoryName = dirToUnzipTo;                 string fileName = Path.GetFileName(myEntry.Name);                 string fileWDir = directoryName + fileName;                 unzippedfile = fileWDir;                  FileStream streamWriter = File.Create(fileWDir);                 int size = 4096;                 byte[] data = new byte[4096];                 while (true)                 {                     size = s.Read(data, 0, data.Length);                     if (size > 0) { streamWriter.Write(data, 0, size); }                     else { break; }                 }                 streamWriter.Close();             }             s.Close();         }         catch (Exception ex)         {             LogStatus.WriteErrorLog(ex, 'ERROR', 'DOViewer.UnZipFile');          }         return (unzippedfile);     } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:15:10+00:00Added an answer on May 10, 2026 at 9:15 pm

    Well, what does the final file look like? (compared to the original). You don’t show the zipping code, which might be part of the puzzle, especially as you are partially swallowing the exception.

    I would also try ensuring everything IDisposable is Dispose()d, ideally via using; also – in case the problem is with path construction, use Path.Combine. And note that if myEntry.Name contains sub-directories, you will need to create them manually.

    Here’s what I have – it works for unzipping ICSharpCode.SharpZipLib.dll:

        private string UnZipFile(string file, string dirToUnzipTo)     {          string unzippedfile = '';          try         {             using(Stream inStream = File.OpenRead(file))             using (ZipInputStream s = new ZipInputStream(inStream))             {                 ZipEntry myEntry;                 byte[] data = new byte[4096];                 while ((myEntry = s.GetNextEntry()) != null)                 {                     string fileWDir = Path.Combine(dirToUnzipTo, myEntry.Name);                     string dir = Path.GetDirectoryName(fileWDir);                     // note only supports a single level of sub-directories...                     if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);                     unzippedfile = fileWDir; // note; returns last file if multiple                      using (FileStream outStream = File.Create(fileWDir))                     {                         int size;                         while ((size = s.Read(data, 0, data.Length)) > 0)                         {                             outStream.Write(data, 0, size);                         }                         outStream.Close();                     }                 }                 s.Close();             }          }         catch (Exception ex)         {             Console.WriteLine(ex);          }         return (unzippedfile);     } 

    It could also be that the problem is either in the code that writes the zip, or the code that reads the generated file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 112k
  • Answers 112k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, you can't manipulate it's behaviour, but you can emulate… May 11, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer Attempt to connect to the SMTP port, and ensure you… May 11, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer The Dictionary(Of TKey,TValue) class is actually serializable but in the… May 11, 2026 at 9:56 pm

Related Questions

I am using the Photoshop's javascript API to find the fonts in a given
I am using the code snippet below, however it's not working quite as I
I am using the AJAX Control Toolkit Popup Calendar Control in a datagrid. When
I am using the tablesorter plugin ( http://tablesorter.com ) and am having a problem

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.