Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ Delphi FoxPro Java Perl Python Ruby SQL Server VBScript
|
Access Denied when Writing ZipI get an "Access is Denied" error when writing a .zip in ASP. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% set zip = Server.CreateObject("Chilkat.Zip2") ' Any string unlocks the component for the 1st 30-days. success = zip.UnlockComponent("Anything for 30-day trial") If (success <> 1) Then Response.Write Server.HtmlEncode(zip.LastErrorText) & "<br>" End If success = zip.NewZip("test.zip") If (success <> 1) Then Response.Write Server.HtmlEncode(zip.LastErrorText) & "<br>" End If ' When a zip is written, the Chilkat Zip component will ' write it to a temp file first. If the entire zip is ' successfully written, then it is moved to it's target filename, ' possibly overwriting an existing file if a .zip having the ' same name already exists. ' The zip.TempDir property indicates the directory where ' the temp zip is written. TempDir defaults to ".", which is ' the current working directory. ' Append a directory tree. recurse = 1 zip.AppendFiles "c:/inetpub/wwwroot/data/*",recurse ' This will most certainly fail. See below for the contents ' of LastErrorText and the explanation. success = zip.WriteZipAndClose() If (success <> 1) Then Response.Write Server.HtmlEncode(zip.LastErrorText) & "<br>" Else Response.Write Server.HtmlEncode("Zip Created!") & "<br>" End If ' The LastErrorText looks something like this: ' WriteZipAndClose: ' DllDate: Sep 7 2007 ' Username: IUSR_CHILKAT ' Component: ActiveX ' tempFile: .\ckz_1KTC.tmp ' loggedOnUser: IUSR_CHILKAT ' curDir: C:\WINDOWS\system32 ' Failed to open file (2) ' ansiFilename: .\ckz_1KTC.tmp ' osErrorInfo: Access is denied. ' CurrentDir: C:\WINDOWS\system32 ' LoggedOnUser: IUSR_CHILKAT ' ansiFilename: .\ckz_1KTC.tmp ' Failed to open output Zip file ' zipFilename: .\ckz_1KTC.tmp ' Retrying with a new temp filename ' Failed to open file (2) ' ansiFilename: .\ckz2_4GUZ.tmp ' osErrorInfo: Access is denied. ' CurrentDir: C:\WINDOWS\system32 ' LoggedOnUser: IUSR_CHILKAT ' ansiFilename: .\ckz2_4GUZ.tmp ' Failed to open output Zip file ' zipFilename: .\ckz2_4GUZ.tmp ' tempFileName: .\ckz2_4GUZ.tmp ' Cannot open temporary file ' The error log tells us that the calling process's current ' working directory is c:\WINDOWS\system32, and it's trying ' to write ".\something.tmp". Obviously that's not going to work ' because you can't write to c:\WINDOWS\system32 from ASP. ' To fix, set the TempDir to a directory that is writable. ' In this case we'll use c:\inetpub\wwwroot\temp, which is ' a virtual directory we've previously setup on this web server ' with write capability. ' Also, if you don't specify a path in NewZip, you're creating ' a zip in the current working directory. Provide a path such ' as c:\inetpub\wwwroot\myZips (you can alternatively use Server.MapPath ' rather than hard-coded absolute paths) ' Now, for the 2nd try, which will work this time: zip.NewZip "c:/inetpub/wwwroot/myZips/test.zip" zip.TempDir = "c:/inetpub/wwwroot/temp" ' Append a directory tree. recurse = 1 zip.AppendFiles "c:/inetpub/wwwroot/data/*",recurse ' Now it worked! success = zip.WriteZipAndClose() If (success <> 1) Then Response.Write Server.HtmlEncode(zip.LastErrorText) & "<br>" Else Response.Write Server.HtmlEncode("Zip Created!") & "<br>" End If %> </body> </html> |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.