Link to home
Start Free TrialLog in
Avatar of jdcoburn
jdcoburn

asked on

zip file open and reading in C#

hi - I'm using VS2010 and .net 4.0 and for program reasons can't upgrade to 4.5. I'm trying to open and read the contents of a zip file so that I can create a data set internal to my program (ie I have no need to create the rest of the zip operation of placing unzipped files somewhere.) I've looked at the Microsoft example code in their Package class that deals with zips and there is reference to an attribute that's not explained. specifically, in the foreach statement to get relationships, the line reads"\
"foreach ( PackageRelationship relationship in documentPart.GetRelationshipByType(ResourceRelationshipType))
the ResourceRelationshipType is undefined if I compile as is. the method is calling for a string, but I don't know where to find the ResourceRelationshipTypes list.
any suggestions?
thanks,
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Please consider using dotnetzip library, for you case:
using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
  foreach (ZipEntry e in zip)
     System.Console.WriteLine(e.FileName); //You could add it to a list, etc.
}

Open in new window

Note: The code sample is a simplified version of Nicholas Carey's answer.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you provide a link to the page that has the code example?
Avatar of jdcoburn
jdcoburn

ASKER

it worked fine, but I had to modify several methods to get it to work.