[
  {
    "Id": "147590",
    "ThreadId": "44340",
    "Html": "I recieve the following security error since using DotNetZip to Extract a .zip file to a trusted folder. I can use the asp:FileUpload component to successfully upload to the same folder that DotNetZip errors.<br>\r\n<br>\r\n[Code]<br>\r\n<br>\r\n<p>using System;<br>\r\nusing System.Collections.Generic;<br>\r\nusing System.Linq;<br>\r\nusing System.Web;<br>\r\nusing System.Web.UI;<br>\r\nusing System.Web.UI.WebControls;<br>\r\nusing System.Net;<br>\r\nusing Ionic.Utils.Zip;<br>\r\nusing System.IO;</p>\r\n<p>public partial class upload : System.Web.UI.Page<br>\r\n{</p>\r\n<p>    protected void Page_Load(object sender, EventArgs e)<br>\r\n    {<br>\r\n    }</p>\r\n<p>    protected void btnFileUpload_Click(object sender, ImageClickEventArgs e)<br>\r\n    {<br>\r\n        HttpFileCollection files = Request.Files;</p>\r\n<p>        for (int i = 0; i &lt; files.Count; i++)<br>\r\n        {<br>\r\n            HttpPostedFile file = files[i];</p>\r\n<p>            if (file.ContentLength &gt; 0)<br>\r\n            {<br>\r\n                file.SaveAs(Server.MapPath(&quot;~/temp/&quot;) + System.IO.Path.GetFileName(file.FileName));<br>\r\n            }<br>\r\n        }    <br>\r\n    }<br>\r\n    protected void btnUnzip_Click(object sender, EventArgs e)<br>\r\n    {<br>\r\n        using (ZipFile zip = ZipFile.Read(FileUpload1.FileName.ToString()))<br>\r\n        {<br>\r\n            foreach (ZipEntry entry in zip)<br>\r\n            {<br>\r\n                entry.Extract(Server.MapPath(&quot;~/temp/&quot;), true);  // overwrite == true<br>\r\n            }<br>\r\n        }      </p>\r\n<p>    }<br>\r\n}<br>\r\n<br>\r\n[DotNetZip Error]<br>\r\n</p>\r\n<h2><i>Security Exception</i> </h2>\r\n<p><span style=\"font-family:arial, helvetica, geneva, sunsans-regular, sans-serif\"><b>Description: </b>The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. <br>\r\n<br>\r\n<b>Exception Details: </b>System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.<br>\r\n<br>\r\n<b>Source Error:</b> <br>\r\n<br>\r\n<table width=\"100%\" bgcolor=\"#ffffcc\">\r\n    <tbody>\r\n        <tr>\r\n            <td><code>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code> </td>\r\n        </tr>\r\n    </tbody>\r\n</table>\r\n<br>\r\n<b><span style=\"font-family:verdana\">Stack Trace:</span></b> <br>\r\n<br>\r\n<table width=\"100%\" bgcolor=\"#ffffcc\">\r\n    <tbody>\r\n        <tr>\r\n            <td><code>\r\n            <pre>[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]\r\n   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet) +0\r\n   System.Security.CodeAccessPermission.Demand() +58\r\n   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) +644\r\n   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +66\r\n   System.IO.File.OpenRead(String path) +30\r\n   Ionic.Utils.Zip.ZipFile.get_ReadStream() +129\r\n   Ionic.Utils.Zip.ZipFile.ReadIntoInstance(ZipFile zf) +454\r\n</pre>\r\n            </code></td>\r\n        </tr>\r\n    </tbody>\r\n</table>\r\n</span></p>\r\n",
    "PostedDate": "2009-01-15T20:02:40.137-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "148087",
    "ThreadId": "44340",
    "Html": "You should set the property TempFileFolder on the ZipFile instance. <br>\r\nThe folder must be writable by your ASP.NET application.<br>\r\n<a href=\"http://forums.iis.net/p/1146752/1858404.aspx\">http://forums.iis.net/p/1146752/1858404.aspx</a>\r\n",
    "PostedDate": "2009-01-18T07:41:46.05-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]