1

I am using below code to unzip my file. It works perfectly on local machine. But when I host this code on server it does Unzip file perfectly, but it waits there to finish something. Don't know why it's waiting.

Shell32.ShellClass sc = new Shell32.ShellClass();

Shell32.Folder SourceFolder = sc.NameSpace(@"C:\TEMP\File.zip");

Shell32.Folder DestFolder = sc.NameSpace(@"C:\TEMP"); 

Shell32.FolderItems items = SourceFolder.Items();

DestFolder.CopyHere(items, 4 | 16);
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 2
    You should also keep in mind that your server may not have a Windows Desktop shell and Shell32 is not available. Using it in server side code is not recommended. – Peter Hahndorf May 25 '15 at 12:09
  • But same code works locally (Locally means via Visual Studio) fine on same machine – sanjay lalwani May 26 '15 at 04:54
  • Yes, because locally you have a desktop machine and not a server without a shell. I'm not saying your problem here is because of that, but that you should not use Shell32 in a server application in general. – Peter Hahndorf May 26 '15 at 05:07

1 Answers1

1

On the server you should avoid using Shell32 functions. They may want to use the desktop or user profile.

There's plenty of other ways to unzip files - you can use System.IO.Compression.ZipFile.ExtractToDirectory or some third-party library or some free command-line tool.

yu_sha
  • 4,290
  • 22
  • 19
  • We are using VSTS 3.5 framework in our project. And when I did Google for System.IO.Compression.ZipFile, its available only for 4.5 framework. Please let me know if I am wrong. – sanjay lalwani May 26 '15 at 04:52
  • You are right. For older .Net versions you can use SharpZipLib or a similar library (see this discussion: http://stackoverflow.com/questions/836736/unzip-files-programmatically-in-net). You can also get a command-line tool such as unzip.exe (e.g. from http://stahlworks.com/dev/?tool=zipunzip) and run it out of process. – yu_sha May 27 '15 at 07:43