[
  {
    "Id": "585050",
    "ThreadId": "250867",
    "Html": "\r\n<p>Hi,</p>\r\n<p>I am using DotNetZip library in sharepoint object model and i am passing the file name as &quot;http://gdot-govm-spd24/info/tpd/Test/Data.txt&quot; and trying to create this file as zip and it throwing me URI formats are not supported. When i use the same file which\r\n is on my local drive, it works perfectly. I am not sure what i am doing wrong here. Please help me.</p>\r\n<p>This is the piece of code i am using here:</p>\r\n<p>using (ZipFile zip = new ZipFile())&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>\r\n<p>{</p>\r\n<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;foreach (string filename in ItemsID)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>\r\n<p><span style=\"white-space:pre\"></span>{&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>\r\n<p><span style=\"white-space:pre\"></span>&nbsp;ZipEntry e = zip.AddFile(filename);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>\r\n<p><span style=\"white-space:pre\"></span>} &nbsp;</p>\r\n<p><span style=\"white-space:pre\"></span>zip.Save(@&quot;C:\\suri.zip&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>\r\n<p>}&nbsp;</p>\r\n<p>Thanks</p>\r\n<p>KPd</p>\r\n",
    "PostedDate": "2011-03-23T07:47:08.98-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "586361",
    "ThreadId": "250867",
    "Html": "<p>no, DotNetZip can read from filesystems.&nbsp; It cannot read from http sources.&nbsp; An easy way to do what you want is to send a GET request to the HTTP&nbsp;resource, and then pass the ResponseStream to the call to AddFile().</p>",
    "PostedDate": "2011-03-25T05:33:19.14-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "678886",
    "ThreadId": "250867",
    "Html": "<p>I am trying to do the same thing but it says URI format not supported. Do you have any example, which can help me fix this issue?</p>",
    "PostedDate": "2011-09-30T19:45:34.79-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "679169",
    "ThreadId": "250867",
    "Html": "<p>There are many variations.&nbsp; One way to do it is to use WebClient to open a stream for the given URL, then call <a href=\"http://cheeso.members.winisp.net/DNZHelp/html/7bc513f6-c21c-6a02-3964-f2a571308a33.htm\">the ZipFile.AddEntry() method that accepts a stream</a>.&nbsp; Something like this would work:</p>\r\n<div style=\"color: black; background-color: white;\">\r\n<pre><span style=\"color: blue;\">string</span> url = <span style=\"color: #a31515;\">\"http://example.org/fi/fie/fo/fum.txt\"</span>;\r\n<span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> zip = <span style=\"color: blue;\">new</span> ZipFile())\r\n{\r\n  <span style=\"color: blue;\">using</span> (WebClient client = <span style=\"color: blue;\">new</span> WebClient())\r\n  {\r\n    <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> s = client.OpenRead(url))\r\n    {\r\n      <span style=\"color: green;\">// s is a readable System.IO.Stream</span>\r\n      zip.AddEntry(<span style=\"color: #a31515;\">\"ThisEntry.txt\"</span>, s);\r\n      <span style=\"color: green;\">// must save the zip (and thereby read the stream) before disposing the stream or WebClient </span>\r\n      zip.Save(<span style=\"color: #a31515;\">\"MyArchive.zip\"</span>);\r\n    }\r\n  }\r\n}\r\n</pre>\r\n</div>\r\n<p>If you have multiple URLs to pack into a single zip file, then you would need to keep all of those streams open at the same time.&nbsp; The basic structure in the snippet above will work for a variable number of URLs, but you'd have to save the zip file for each additional URL added, which is very much non-optimal.&nbsp;</p>\r\n<p>What you'd like to do is open the stream only as necessary during the save operation. This is possible using <a href=\"http://cheeso.members.winisp.net/DNZHelp/html/88e02061-3787-c10b-8522-a9e045f0bd94.htm\">the ZipFile.AddEntry() method that accepts an OpenDelegate and a CloseDelegate</a>. In this approach, your code opens the stream&nbsp;within the context of the save operation.&nbsp;&nbsp;It looks like this:</p>\r\n<div style=\"color: black; background-color: white;\">\r\n<pre><span style=\"color: blue;\">string</span>[] urls = {\r\n    <span style=\"color: #a31515;\">\"http://example.org/whatever.txt\"</span>,\r\n    <span style=\"color: #a31515;\">\"http://example.org/whatever2.txt\"</span>,\r\n    <span style=\"color: #a31515;\">\"http://example.org/whatever3.txt\"</span>\r\n  }; \r\n\r\n<span style=\"color: blue;\">var</span> getOpener = <span style=\"color: blue;\">new</span> Ionic.Zip.OpenDelegate( name =&gt; {\r\n   <span style=\"color: green;\">// GetUrlForEntryName is your custom function...</span>\r\n   <span style=\"color: blue;\">var</span> url = GetUrlForEntryName (name);\r\n   WebClient c = <span style=\"color: blue;\">new</span> WebClient();\r\n   <span style=\"color: blue;\">return</span> c.OpenRead(url);\r\n});\r\n\r\n<span style=\"color: blue;\">var</span> closer = <span style=\"color: blue;\">new</span> Ionic.Zip.CloseDelegate( (name, stream) =&gt; {\r\n   stream.Dispose();\r\n});\r\n\r\n<span style=\"color: blue;\">using</span>(<span style=\"color: blue;\">var</span> zip = <span style=\"color: blue;\">new</span> Ionic.Zip.ZipFile())\r\n{\r\n    <span style=\"color: blue;\">for</span>(<span style=\"color: blue;\">int</span> i=0; i&lt;urls.Length; i++) \r\n    {\r\n        <span style=\"color: green;\">// GetEntryNameForUrl is your custom function...</span>\r\n        <span style=\"color: blue;\">var</span> entryName = GetEntryNameForUrl(urls[i]);\r\n        zip.AddEntry(entryName, getOpener, closer);\r\n    }\r\n    zip.Save(zipFileName);\r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;&nbsp;</p>",
    "PostedDate": "2011-10-02T16:03:30.61-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1323516",
    "ThreadId": "250867",
    "Html": "Thanks Cheeso, here is a slightly simpler multi-file version in VB<br />\n<pre><code>Dim pdfs As New List(Of Tuple(Of String, String))\npdfs.Add(New Tuple(Of String, String)(&quot;MyFileNameInZip&quot;, &quot;http://urlToFile.pdf&quot;))\nIf pdfs.Count &gt; 0 Then\n    Dim getOpener = New Ionic.Zip.OpenDelegate(Function(name) New WebClient().OpenRead(pdfs.FirstOrDefault(Function(x) x.Item1 = name).Item2))\n    Dim closer = New Ionic.Zip.CloseDelegate(Sub(name, stream) stream.Dispose())\n    Using zip = New Ionic.Zip.ZipFile()\n        For Each pdf In pdfs\n            zip.AddEntry(pdf.Item1, getOpener, closer)\n        Next\n        Response.ContentType = &quot;application/zip&quot;\n        Response.AddHeader(&quot;Content-Disposition&quot;, &quot;filename=MyZipFile.zip&quot;)\n        zip.Save(Response.OutputStream)\n    End Using\nEnd If</code></pre>\n\n",
    "PostedDate": "2014-11-18T11:00:28.07-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1467670",
    "ThreadId": "250867",
    "Html": "Hi Cheeso,\r<br />\n<br />\nI need to pack multiple uri's into a single Zip file, in which the above code is working fine when I tested using sample win forms application.\r<br />\n<br />\nMy requirement is how to use this to return a Zip file stream using web api when the user clicks on donwload ?  we are using web api +angularJs.<br />\n",
    "PostedDate": "2016-03-22T11:48:56.207-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1467671",
    "ThreadId": "250867",
    "Html": "Hi Cheeso, \r<br />\n<br />\nI need to pack multiple uri's into a single Zip file, in which the above code is working fine when I tested using sample win forms application. \r<br />\n<br />\nMy requirement is how to use this to return a Zip file stream using web api when the user clicks on donwload ? we are using web api +angularJs.<br />\n",
    "PostedDate": "2016-03-22T11:49:15.723-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1467673",
    "ThreadId": "250867",
    "Html": "I need to pack multiple uri's into a single Zip file, in which the above code is working fine when I tested using sample win forms application. \r<br />\n<br />\nMy requirement is how to use this to return a Zip file stream using web api when the user clicks on donwload ? we are using web api +angularJs.<br />\n",
    "PostedDate": "2016-03-22T11:50:45.377-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]