views:

1523

answers:

2

Ok,

I have a list of files (SourceFile objects which just contain the filename only)

then I want to pull those specific files out of a zip and dump them into a temp directory

so I can distribute them later.

I came up with this, but I am unsure on how to proceed next..

private List ExtractSelectedFiles() { List zipFilePaths = new List(); List tempFilePaths = new List();

if (!File.Exists(this.txtSourceSVNBuildPackage.Text)) { return tempFilePaths; };

FileStream zipFileStream = File.OpenRead(this.txtSourceSVNBuildPackage.Text);
ZipInputStream inStream = new ZipInputStream(zipFileStream);

foreach (SourceFile currentFile in _selectedSourceFiles)
{
 bool getNextEntry = true;

 while (getNextEntry)
 {
         ZipEntry entry = inStream.GetNextEntry();

  getNextEntry = (entry != null);

                if (getNextEntry)
         {
       if (fileType == ".dll")
       {
       if (sourcefile.Name == Path.GetFileName(entry.Name))
       {
    //Extract file into a temp directory somewhere

    //tempFilePaths.Add("extractedfilepath")
       }
       }
         }
          }
      }

    return tempFilePaths;

}

FYI:

public class SourceFile
{
 public string Name { get; set; }  //ex. name = "Fred.dll"
}
+1  A: 

ok.. figured I'd update you all after I got together the missing piece I needed.

//in the code somewhere above:
string tempDirectory = Environment.GetEnvironmentVariable("TEMP");
string createPath = tempDirectory + "\\" + Path.GetFileName(entry.Name);


//my missing piece..
//Extract file into a temp directory somewhere
FileStream streamWriter = File.Create(createPath);

int size = 2048;
byte[] data = new byte[2048];
while (true)
{
    size = inStream.Read(data, 0, data.Length);
    if (size > 0)
    {
     streamWriter.Write(data, 0, size);
    }
    else
    {
     break;
    }
}

streamWriter.Close();
KevinDeus
A: 

Heh.. found this after I did everything..

http://stackoverflow.com/questions/328343/using-sharpziplib-to-unzip-specific-files

KevinDeus