Unzip Author information

Oct 5, 2011 at 1:56 PM

All,

I recently downloaded this library and in the process of evaluating for my project.

I have a requirement where I'd like to know the person who unzipped the file.

Is there a way I can enter the name of the person who unzipped the file.

PS: I used the "Comment" attribute while unzipping the file

zip.ToList().Where(s => !s.IsDirectory && Path.GetExtension(s.FileName) == ".xyz").ToList().ForEach(entry =>                            {                                entry.FileName = Path.GetFileName(entry.FileName);                                entry.CreationTime = DateTime.Now;                                entry.Comment = sUser;                                entry.Extract(sUnpackDirectory, ExtractExistingFileAction.OverwriteSilently);                            });

However I am unable to get that information from the following code 

FileInfo[] fiFiles = new DirectoryInfo(sFileUploadLocation).GetFiles("*.*");

Am I missing something ?

Regards,

Kaushik

Coordinator
Oct 5, 2011 at 4:17 PM
Edited Oct 5, 2011 at 4:18 PM

#1, The code you provided is completely misformatted. I can't see what you're doing there.  Try using the <CODE> button on the post editor.

#2 - I don't know what you mean by "is there a way I Can enter the name who unzipped the file".    Your program creates a zip file, right?  then you send the zipfile to someone in Peoria.  They may unzip the zipfile, or they may not.  They may hand off the zipfile to their aunt in Kalamazoo.  She may unzip the zipfile.  You don't have control over who does or does not unzip the file. a zipfile is an archive format that can be read by many many tools, and you don't have control over those tools.

You could produce a program that opens a zipfile only after someone enters a name. But that program would be something you write. Also it would not prevent Aunt Molly in Kalamazoo from using Windows Explorer to open the zipfile, which does not require entering a name. 

if this doesn't answer your question, maybe you could explain more about your specific goal. 

Also, if you provide code, check the formatting.

 

Oct 5, 2011 at 4:39 PM
Edited Oct 5, 2011 at 7:11 PM

i have formatted the code below

 

// Remove the directory part of the filename just prior to unzipping
// extracting only .xyz files
zip.ToList().Where(s => !s.IsDirectory && Path.GetExtension(s.FileName) == ".xyz").ToList().
                        ForEach(entry =>
                            {
                                entry.FileName = Path.GetFileName(entry.FileName);
                                entry.CreationTime = dtUploadTime;
                                entry.Comment = sUser;
                                entry.Extract(sUnpackDirectory, ExtractExistingFileAction.OverwriteSilently);
                            });

 

Not withstanding the folks all around the globe, I have a requirement where the user uploads a zip file and that information needs to be shown on the webpage. When the user uploads the zip file I unzip it to a folder and delete the original zip file. Lets say the contents of the zip file are 1.xyz and 2.xyz and is being uploaded by Aunt Molly.

In the aforementioned code I have set the comment attribute as sUser. (sUser = "Aunt Molly';)

While displaying the results in the UI, one would like to display that Aunt Molly uploaded 1.xyz and 2.xyz. I am getting the file information using the following code

 

FileInfo[] fiFiles = new DirectoryInfo(sFileUploadLocation).GetFiles("*.xyz");

 

Is there a way to retrieve "Aunt Molly"s name ?

PS: I modified the code to the following 

 

foreach (var fileInfo in fiFiles)
                {
                    FileVersionInfo fileVersInfo = FileVersionInfo.GetVersionInfo(fileInfo.FullName);
                    String sComments = fileVersInfo.Comments;
                }

 

the comments is always null.

when we set

entry.Comment =  "Aunt Molly';

 what  exactly is being set ?

let me know if you need anything else ?

Regards,

Kaushik

Coordinator
Oct 6, 2011 at 4:44 AM

entry.Comment is a property on the ZipEntry class.  If you set this property, and then call ZipFile.Save, the value of the property is stored in the zipfile.  It will then be viewable by a zipfile-reader applicaiton, the next time the zipfile is read. If you set this property and don't call save, the Comment is not saved in the zipfile.

From your question I think that you are expecting that if you set the entry.Comment, and then Extract the entry, something happens in the filesystem with the value of the Comment. I cannot imagine where you got that idea.  After you extract entries from the zipfile, and delete the zipfile, the Comment information that may have been stored on any of the entries stored in the zipfile, is gone. That information is used and is relevant only within the zipfile itself.  For full details, check the documentation on ZipEntry.Comment and ZipEntry.Extract. 

Also, check the documentation on FileVersionInfo.  It tells you:

> The FileVersionInfo properties are based on version resource information built into the file. Version resources are often built into binary files such as .exe or .dll files; text files do not have version resource information.

I think that your problem is solvable, but I don't think that a different usage of the zip library is the solution.

 

 

Coordinator
Oct 6, 2011 at 4:45 AM

Why don't you just extract the zip from Molly into a directory named "Molly" ?