[
  {
    "Id": "508345",
    "ThreadId": "231182",
    "Html": "<p>Hi guys,</p>\r\n<p>Totally hit the wall and cant get my head around the issue. Basically I built a simple ASP.NET (C#) app, based on the example, which  reads files from a particular folder within the VS2010 project, fills  the checkbox list with the file names, then you tick appropriate boxes  to indicate which files you want to zip. Once download button is pressed  the resulting zip file is prepared and sent back by the browser.</p>\r\n<p>The problem I am hitting is that when the download button is pressed I get the following Exception:</p>\r\n<p>System.IO.FileNotFoundException: C:\\Program Files\\Common Files\\Microsoft Shared\\DevServer\\10.0\\test.pdf, test.pdf is one of the files which I tick to include in the zip. The VS2010 informs me that the exception corresponds to the line where this code resides - zfZip.Save(Response.OutputStream);</p>\r\n<p>So for some reason &quot;something&quot; is looking into the DevServer\\10.0\\ folder for files to zip instead of the&nbsp; Downloads directory within the project. I am not not quite sure why this is happening, perhaps something needs to be configured, but I am not sure what...</p>\r\n<p>I'd be grateful if someone could point me in a right direction of where to dig to find a solution for the issue.</p>\r\n<pre><span style=\"color:blue\">\r\n</span></pre>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre><span style=\"color:blue\"><div style=\"color:black;background-color:white\"><pre><span style=\"color:blue\">public</span> <span style=\"color:blue\">partial</span> <span style=\"color:blue\">class</span> _Default : System.Web.UI.Page\r\n    {\r\n        <span style=\"color:blue\">protected</span> <span style=\"color:blue\">void</span> Page_Load(<span style=\"color:blue\">object</span> sender, EventArgs e)\r\n        {\r\n            <span style=\"color:blue\">if</span> (!Page.IsPostBack)\r\n            {\r\n                DirectoryInfo dirInfo = <span style=\"color:blue\">new</span> DirectoryInfo(Server.MapPath(<span style=\"color:#a31515\">&quot;~/Downloads/&quot;</span>));\r\n                cblFiles.DataSource = dirInfo.GetFiles();\r\n                cblFiles.DataBind();\r\n\r\n            }\r\n        }\r\n\r\n        <span style=\"color:blue\">protected</span> <span style=\"color:blue\">void</span> btnDownload_Click(<span style=\"color:blue\">object</span> sender, EventArgs e)\r\n        { <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color:blue\">string</span> message = <span style=\"color:#a31515\">&quot;You must select one or more files to download.&quot;</span>;\r\n            <span style=\"color:blue\">string</span> strZipFileName;\r\n            <span style=\"color:blue\">string</span> strReadme;\r\n\r\n            <span style=\"color:blue\">if</span> (cblFiles.SelectedItem == <span style=\"color:blue\">null</span>)\r\n            {\r\n                ClientScript.RegisterStartupScript( <span style=\"color:blue\">this</span>.GetType(), Guid.NewGuid().ToString(),\r\n                        <span style=\"color:blue\">string</span>.Format(<span style=\"color:#a31515\">&quot;alert('{0}');&quot;</span>, message.Replace(<span style=\"color:#a31515\">&quot;'&quot;</span>, <span style=\"color:#a31515\">@&quot;\\'&quot;</span>)),<span style=\"color:blue\">true</span>);\r\n                <span style=\"color:blue\">return</span>;\r\n            }\r\n\r\n            strZipFileName = <span style=\"color:blue\">string</span>.Format(<span style=\"color:#a31515\">&quot;Download - {0}.zip&quot;</span>, DateTime.Now.ToString(<span style=\"color:#a31515\">&quot;yyyy-MM-dd-HH_mm_ss&quot;</span>));\r\n            Response.ContentType = <span style=\"color:#a31515\">&quot;application/zip&quot;</span>;\r\n            Response.AddHeader(<span style=\"color:#a31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#a31515\">&quot;filename=&quot;</span>+strZipFileName);\r\n\r\n            <span style=\"color:blue\">using</span> (ZipFile zfZip = <span style=\"color:blue\">new</span> ZipFile())\r\n            {\r\n                <span style=\"color:blue\">if</span> (!<span style=\"color:blue\">string</span>.IsNullOrEmpty(txtZipPassword.Text))\r\n                {\r\n                    zfZip.Password = txtZipPassword.Text;\r\n                    zfZip.Encryption = EncryptionAlgorithm.WinZipAes128;\r\n                }\r\n\r\n                strReadme = <span style=\"color:blue\">string</span>.Format(<span style=\"color:#a31515\">&quot;Your ZIP file {0} contains the following files:{1}{1}&quot;</span>, strZipFileName,Environment.NewLine);\r\n\r\n                <span style=\"color:blue\">foreach</span> (ListItem li <span style=\"color:blue\">in</span> cblFiles.Items)\r\n                {\r\n                    <span style=\"color:blue\">if</span> (li.Selected)\r\n                    {\r\n                        strReadme += <span style=\"color:blue\">string</span>.Concat(<span style=\"color:#a31515\">&quot;\\t*&quot;</span>, li.Text, Environment.NewLine);\r\n                        zfZip.AddFile(li.Value);\r\n\r\n                    }\r\n                }\r\n\r\n                zfZip.AddEntry(<span style=\"color:#a31515\">&quot;readme.txt&quot;</span>, strReadme);\r\n                zfZip.Save(Response.OutputStream);\r\n            }\r\n\r\n        }\r\n    }\r\n</pre>\r\n</div>\r\n<br></span></pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-10-16T17:02:38.377-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "508712",
    "ThreadId": "231182",
    "Html": "<p>Hi Andrew,</p>\r\n<p>Is your &quot;li.Value&quot; a fully qualified path, or just a file name? I've not looked at the DotNetZip source code to confirm, but I'm guessing AddEntry will use the current working directory if you don't specify which one the file is in. In your case this is &quot;C:\\Program Files\\...\\DevServer\\10.0&quot;.</p>\r\n<p>You might need to use something like this instead:</p>\r\n<p>zfZip.AddFile(Server.MapPath(&quot;~/Downloads/&quot;) + li.Value);</p>\r\n<p>Hope this helps,</p>\r\n<p>Mike</p>",
    "PostedDate": "2010-10-18T02:52:58.207-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "508726",
    "ThreadId": "231182",
    "Html": "<p>Hi Mike,</p>\r\n<p>Thanks for your reply, worked perfectly after I added - &quot;Server.MapPath(&quot;~/Downloads/&quot;) +&quot; since &quot;li.Value&quot; did contain only the filename.</p>\r\n<p>Cheers for that buddy!!!</p>\r\n<p>&nbsp;</p>\r\n<p>Andrew</p>",
    "PostedDate": "2010-10-18T03:42:58.173-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]