First of all, I clear that I am using ASP.NET 4.5 with DefaultAppPool(integrated 4.0). I have also configured Anonymous Access to DefaultAppPool user. I have given all access to DefaultAppPool. System.Security.Principal.WindowsIdentity.GetCurrent()
method give me the same user. But when the following line runs it gives me Access to the path 'XXXX' is denied.
exception. Then for testing purpose, I have given all rights to EveryOne
user but still getting the same error. Here is the line of code. Note the trus
using (ZipArchive archive = new ZipArchive(zipStream))
{
foreach (ZipArchiveEntry file in archive.Entries)
{
file.ExtractToFile(location,true);
}
}
Here is the StackTrace,
[UnauthorizedAccessException: Access to the path 'XXX' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10793558
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1352
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +65
System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite) +96
XX.XX.XX.ExtractZipFile(Stream zipStream, String location) in XX.cs:44
XX.XX.XX.XX.XX.XX.ExtractZipFile(Stream zipStream, String location) in XXX.cs:17
.NET framework in this case giving me the wrong exception. The problem was that, I was just passing location(folder location without file name). So after including complete path, this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With