k.troy2012 k.troy2012 -3 years ago 197
reST (reStructuredText) Question

C# write stream into a .zip-file on Windows IoT

I've written an UWP-App to download files via REST-Requests.
The App runs on a Raspberry Pi 3 with Windows IoT.

I want to write 'testStream' into a .zip-File and download it.
Here is my code:

Uri uri = new Uri("http://xxxx:3080/cds/api/download/book/46795403-de-DE");
HttpWebRequest getRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
getRequest.Method = "GET";
getRequest.Headers["Authorization"] = "Bearer xyxyxy";
HttpWebResponse response2 = await getRequest.GetResponseAsync() as HttpWebResponse;
StreamReader streamReader2 = new StreamReader(response2.GetResponseStream());
Stream testStream = response2.GetResponseStream();
getResult = streamReader2.ReadToEnd();
textBox2.Text = getResult;

await Task.Run(() =>
using (var fs = File.Create("\\myZipDownload.zip"))

I'm getting this error:

"Access to the path 'C:\myZipDownload.zip' is denied."

Answer Source

You need a writable destination.

You can use Environment.GetFolderPath to get a writable path.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download