|
 |
|
|
Hello:
I'm trying to understand why the following call results in a null value: Shell32.Folder DestFlder = sc.NameSpace(dest); where dest = "C:\Documents and Settings\andrea.washington\My Documents\Visual Studio 2008\Projects\HorizonReportResend\bin\Debug\horizonResend"
Yes the folder does exist and yes I have put quotation marks around the path. I tried using the sample app thinking it was my code but the same thing happens using the sample app. I have tried putting the horizonResend folder in different spots under C:\Documents and Settings but still get a file not found message. The call works fine if the horizonResend folder is on the root of C (C:\horizonResend).
Any ideas??
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I created the exact path you mentioned and used this code which did not result in a null... see if this works...
Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFlder = sc.NameSpace(@"C:\Documents and Settings\andrea.washington\My Documents\Visual Studio 2008\Projects\HorizonReportResend\bin\Debug\horizonResend");
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Any tips on debugging this when something goes wrong? I wrapped this up in an assembly, and am using this in a web application to zip and stream files to the user. Everything works great on my dev machine, however when I deploy it to a test machine, it creates the ZIP folder, but never adds any files to it, and finally just times out.
I've verified the file paths are correct, the IIS user it runs under has read/write permissions on the folder, and I'm pretty much stuck at this point trying to figure out what I'm doing wrong.
Any help would be appreciated.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
I would make it print out a trace after each line of code into a text file and then look at that text file after a failure. This might tell you which line of code is the problem. You might also try wrapping the code in a try catch and writing out the error message if any as well. I have not seen the decompress fail myself so no real life tips to give.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I am using sample code and run this project and select the source path and destination path and zip file name but whenever i click the zip button it gives the error (The system cannot find the file specified)win32 exception was unhandled. pls help to run this code successfully. Amit Saxena
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, 1) Is there a hack or a straight forward way to ignore the subfolders within the archive and decompress them in the same directory? For example instead of decompressing in "C:\Temp\DecompressedFilesHere", it should decompress in C:\Temp
2) Can this method be used to decompress the files from a .tar archive ?
Thank you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Unfortunately I believe the answer to both your questions is no. This method uses the zip functionality built into Windows and I have never seen Windows zip ability used with tar files.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi,
First of all thanks for your code - it works great. But i have a requirement where i have to decompress password protected zip file. Any idea how to go about it?
Regards, Venkatesh.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for the complement. I will think about it some more, however right now I would have to guess this is not possible since the Windows Shell API does not allow you to set a password when ziping a file. So I would also guess that it cannot supply a password when decompressing. If I find a solution I will post it by this weekend.
-- modified at 22:26 Thursday 22nd February, 2007
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
this line is used to compress a folder and it works:
new ShellClass().NameSpace(file).CopyHere(new ShellClass().NameSpace(folder).Items(), 20);
this line is used to decompress a file and it doesnt work:
new ShellClass().NameSpace(folder).CopyHere(new ShellClass().NameSpace(file).Items(), 20);
it is the same as what is in your tutorial but in one line. it should work. but it doesnt.
the compressing code line results in a zip file that works fine. the decompressing code line results in removing all files in the zip file and extracting nothing.
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
I am having a problem when I run this on Win2K advanced server. Are the shell api's supported on this platform?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi,
I want to set the overwrite option of DestFlder.CopyHere(items, 20) to "Yes To All". What is the option value I should use, or where can I get a list of the .CopyHere() option values?
e-dub
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi, I am using this tutorial to partial satisfaction. 
I cannot no matter what I doget it to do Yes To All on the dialog boxes.
20, as in the tutorial by my reconing should be Yes To All and No File copy dialog
16 = Yes To All 4 = No copy file dialog
I have tried 16 on its own as
0x14, 0x0014, 16 and combined with 4 as 20.
Yet to no avail I still always get asked if I want to overrite the file.
The function in situe (Without the extra returns mid comamnd thats just to make it readable here) is as follows:
public static void unzip(int UpdateNumber) { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFlder = sc.NameSpace( String.Format("{1}\\{0}.zip", UpdateNumber, System.Environment.CurrentDirectory) ); Shell32.Folder DestFlder = sc.NameSpace( String.Format("{0}\\", System.Environment.CurrentDirectory) );
Shell32.FolderItems items = SrcFlder.Items();
DestFlder.CopyHere(items, 20);
File.Delete( String.Format("{1}\\{0}.zip", UpdateNumber, System.Environment.CurrentDirectory) ); }
It is part of a distributable update program I have wished to implement for a while now, and I don't trust the user to always click yes to all.
Am I flogging a dead horse? Will this work?
Many Thanks Hugh Wood IMRI Technical Services
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
What I have found is the vOptions parameter does not work. This is what led me to making this article in the first place. I wanted to use the vOptions paramter '4' to tell it to NOT display a dialog box at all... but it simply does not work. To get around this I used the console app approach where I can tell it to not show any output.
You probably have already found this page, but just in case ... Microsoft's reference says...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/folder/copyhere.asp[^]
vOptions Optional. Specifies options for the copy operation. This value can be zero or a combination of the following values. These values are based upon flags defined for use with the fFlags member of the C++ SHFILEOPSTRUCT structure. These flags are not defined as such for Microsoft Visual Basic, Visual Basic Scripting Edition (VBScript), or Microsoft JScript, so you must define them yourself or use their numeric equivalents.
4 Do not display a progress dialog box. 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. 16 Respond with "Yes to All" for any dialog box that is displayed. 64 Preserve undo information, if possible. 128 Perform the operation on files only if a wildcard file name (*.*) is specified. 256 Display a progress dialog box but do not show the file names. 512 Do not confirm the creation of a new directory if the operation requires one to be created. 1024 Do not display a user interface if an error occurs. 2048 Version 4.71. Do not copy the security attributes of the file. 4096 Only operate in the local directory. Don't operate recursively into subdirectories. 9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.
-- modified at 13:22 Tuesday 18th July, 2006
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Ok ty, what I will do is checkif the file exists first using IO and delete it, the only problem then is the folders because if the other optiosn dont work, I doubt 512 works, I will try.
Thank you for your instantanious response.
Hugh Wood Imri Technical Services
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
When I try and zip a large group of files directly from the console app, i'm finding that it is stopping after the in-built delay (default 1s) is reached, leaving a large amount of my files "unzipped" - i.e. left out of the zip file. If I increase the delay, the program will zip more of the files - but this is not an ideal solution.
I haven't tried using the front-end app, as my final app that this will be used in will be console only, and i'm not concerned about the popup progress bar.
I've tried putting the main logic into it's own thread, and from Main() monitoring the IsAlive property with a while loop - puttting repeated delays into the loop body, but this has the same effect as putting all the code into Main().
Is there any way of keeping the thing running until the zip file has been completely created?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Sorry it has taken me so long to get back to you. I have been very busy. However I was able to reproduce your issue and came up with this code... It replaces the entire zip class in the console app. Basically I never tested the console app with a large source to zip. This code solves the issue by 1) Setting a timeout incase you do not want to continue ziping beyond a certain time period ... 2) checking the number of FolderItems in the source and comparing that number to the number of FolderItems in the new zip file every few seconds 3) looping over and over until the number of FolderItems in the zip matches the number in the source folder (which means the zip process is finished) and THEN the console app exits... I will add more to the article later to include this code.
The one issue I ran into however with this code is that an error pops up from Windows saying that it can not put empty folders into a zip IF you happen to have an empty folder in the source your are ziping. If you use the right click in Windows to zip the very same folder heirarchy with an empty folder no such error occurs ... I do not know why it does occur when you call the Shell API yourself, but it does. You could loop through your source and if you find any folders that are empty either delete them or put a small text file in them or something automatically so that Windows will not throw that error (which stops the zip process)
using System; using System.IO;
namespace zip { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { //Create an empty zip file byte[] emptyzip = new byte[] { 80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
FileStream fs = File.Create(args[1]); fs.Write(emptyzip, 0, emptyzip.Length); fs.Flush(); fs.Close(); fs = null;
//Copy a folder and its contents into the newly created zip file Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFlder = sc.NameSpace(args[0]); Shell32.Folder DestFlder = sc.NameSpace(args[1]); Shell32.FolderItems items = SrcFlder.Items();
//Count the number of FolderItems in the original source location int OriginalItemCount = RecurseCount(items);
//Start the ziping DestFlder.CopyHere(items, 1024);
//Timeout period... if the compression is not done within this time //limit then the zip.exe shuts down and the ziping is stoped DateTime timeoutDeadline = DateTime.Now.AddMinutes(30);
//Wait until the ziping is done. for( ;; ) { //Are we past the deadline? if(DateTime.Now > timeoutDeadline) { break; }
//Check the number of items in the new zip to see if it matches //the number of items in the original source location
//Only check the item count every 5 seconds System.Threading.Thread.Sleep(5000);
if(OriginalItemCount == RecurseCount(DestFlder.Items())) { break; } } }
private static int RecurseCount(Shell32.FolderItems Source) { int ItemCount = 0;
foreach(Shell32.FolderItem item in Source) { if(item.IsFolder == true) { ItemCount++; ItemCount += RecurseCount(((Shell32.Folder)item.GetFolder).Items()); } else { ItemCount++; } }
return ItemCount; } } }
-- modified at 14:32 Thursday 2nd March, 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
When I try your code out I get the following exception:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll
Additional information: The system cannot find the file specified
I can't tell if it can't find the zip file, or can't find unzip.exe. I originally thought I just implemented your code incorrectly, but I just downloaded your solution and got the same problem. I've tried multiple zip files with different output folders, under win2k and xp.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Sorry I don't have an exact answer, but if I get more info I can probably help. I wonder what file it cannot find? Do you have the file Interop.Shell32.dll in the application folder with the unzip.exe? Are you sure the path to the zip file is correct?
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |