memorystream

Read ionic Zip as Memory Stream C#

自闭症网瘾萝莉.ら 提交于 2019-12-04 02:04:22
I am using Ionic.Zip to extract ZipFile to memory stream with this method: private MemoryStream GetReplayZipMemoryStream() { MemoryStream zipMs = new MemoryStream(); using (ZipFile zip = ZipFile.Read(myFile.zip)) { foreach (ZipEntry zipEntry in zip) { if (zipEntry.FileName.StartsWith("Aligning") || zipEntry.FileName.StartsWith("Sensing")) { zipEntry.Extract(zipMs); } } } zipMs.Seek(0, SeekOrigin.Begin); return zipMs; } Once I am done extracting, I want to read the streams and get some of the entries based on the entry filename. How can I do that? I tried by calling with the code below, but I

Why does MemoryStream.GetBuffer() always throw?

萝らか妹 提交于 2019-12-03 23:35:52
问题 The following code will always throw UnuthorizedAccessException (MemoryStream's internal buffer cannot be accessed.) byte[] buf1 = { 2, 3, 5, 7, 11 }; var ms = new MemoryStream(buf1); byte[] buf2 = ms.GetBuffer(); // exception will be thrown here This is in a plain old console app and I'm running as an admin. I can't imagine a more privileged setting I could give this code. So why can't I get at this buffer? (And if nobody can, what's the point of the GetBuffer method?) The MSDN docs say To

MemoryStream have one thread write to it and another read

前提是你 提交于 2019-12-03 23:00:26
This is how I write to a stream then read from it using 1 thread: System.IO.MemoryStream ms = new System.IO.MemoryStream(); // write to it ms.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 7); // go to the begining ms.Seek(0, System.IO.SeekOrigin.Begin); // now read from it byte[] myBuffer = new byte[7]; ms.Read(myBuffer, 0, 7); Now I was wondering if it is possible to write to the memory-stream from one thread and read that stream from a separate thread. You can't use a Stream with seeking capabilities from 2 threads simultaneous since a Stream is state full. e.g. A NetworkStream has 2 channels

Does a Stream get Disposed when returning a File from an Action? [duplicate]

ぐ巨炮叔叔 提交于 2019-12-03 16:51:55
问题 This question already has answers here : Does FileStreamResult close Stream? (1 answer) How do I dispose my filestream when implementing a file download in ASP.NET? (2 answers) Closed 2 years ago . I'm writing a string to a MemoryStream I need to return the stream to the Controller Action so I can send it off as a file for download. Normally, I wrap the Stream in a using statement, but, in this case, I need to return it. Does it still get Disposed after I return it? Or do I need to dispose it

Download blob storage and return Json object

我与影子孤独终老i 提交于 2019-12-03 15:42:06
I am trying to download a .json blob that I have stored in a container in the Azure Storage using Newtonsoft.Json to write it to an object. I am doing this by calling: (CloudBlockBlob) blob.DownloadToStream(stream); However, instead of writing the stream to a file in the local app directory, I want to return the json object doing Json(result) This is what I have tried: using (var stream = new MemoryStream()) { blob.DownloadToStream(stream); var serializer = new JsonSerializer(); using (var sr = new StreamReader(stream)) { using (var jsonTextReader = new JsonTextReader(sr)) { result =

FileStream not closing file

北战南征 提交于 2019-12-03 12:43:27
I have the following code: using (MemoryStream str = new MemoryStream()) { Program.api.GetDocument(result, str); using (FileStream fileStream = File.Create(filePath)) { str.WriteTo(fileStream); } } Whenever a file is written, it is always locked afterwards - attempting to delete it or modify it causes Windows to tell me the file is in use, even after closing my application. Am I missing something? Your problem is most likely caused by Windows Search Indexing which is a part of Windows Search . If you attempt to access the file immediately (or very shortly) after modifying it, you may run into

Get Imagesource from Memorystream in c# wpf

给你一囗甜甜゛ 提交于 2019-12-03 09:59:12
How can I get ImageSource from MemoryStream in WPF using c# ? or convert MemoryStream to ImageSource to display it as image in wpf ? using (MemoryStream memoryStream = ...) { var imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = memoryStream; imageSource.EndInit(); // Assign the Source property of your image image.Source = imageSource; } 来源: https://stackoverflow.com/questions/6588974/get-imagesource-from-memorystream-in-c-sharp-wpf

Saving a bitmap into a MemoryStream

岁酱吖の 提交于 2019-12-03 09:34:19
Should I allocate the memory or just the object of the memory stream: Is this OK? MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); If I need to define the MemoryStream size, how can I get it from Bitmap? .NET is a managed environment: specifically, memory allocation is usually managed on your behalf by the .NET runtime. You don't typically need to allocate the memory yourself. Sometimes, however, you do need to inform the runtime when you've finished with memory by using Close() or Dispose() . The using statement can be used to

Name cannot begin with the ' ' character

喜欢而已 提交于 2019-12-03 09:23:09
I'm parsing some XML in C#. I'm getting it from a database, and so converting it to a MemoryStream before reading it with an XmlTextReader. The problem is that I get this error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3. Following is my XML and my code for reading it (it's coming out of the database alright, no blank first character). Any suggestions? XML: <? xml version="1.0" encoding="utf-8" ?> <form> <e order="0" type="custom" name="test"> <fi type="text" /> <o /> </e> <e order="1" type="zip" /> <e order="2" type="state" /> </form> C#: byte[]

Does a Stream get Disposed when returning a File from an Action? [duplicate]

廉价感情. 提交于 2019-12-03 06:09:31
This question already has answers here : Does FileStreamResult close Stream? (1 answer) How do I dispose my filestream when implementing a file download in ASP.NET? (2 answers) I'm writing a string to a MemoryStream I need to return the stream to the Controller Action so I can send it off as a file for download. Normally, I wrap the Stream in a using statement, but, in this case, I need to return it. Does it still get Disposed after I return it? Or do I need to dispose it myself somehow? //inside CsvOutputFormatter public Stream GetStream(object genericObject) { var stream = new MemoryStream()