memorystream

How to Dispose a list of objects;Does it Free the Memory [duplicate]

99封情书 提交于 2019-12-24 16:46:29
问题 This question already has answers here : Understanding garbage collection in .NET (3 answers) Closed 4 years ago . I have the following class. public class Foo { private string _DirName; private FileStream _MyfileStream; public FileStream MyfileStream { get { return _MyfileStream; } } public string DirName { get { return _DirName; } set { _DirName = value; _MyfileStream = new FileStream(value, FileMode.Create); } } } I have Created a List Of Foo as like the following: List<Foo> FooList = new

How can I assign the contents of an iTextSharp.text.Document to either a byte array or a Memory Stream?

我的未来我决定 提交于 2019-12-24 15:51:59
问题 I have working code in an ASP.NET Web API app that downloads an Excel spreadsheet / .xls file to the user's machine when this method is called via a click on a link: public HttpResponseMessage Get(string unit, string begindate, string enddate) { byte[] excelContents; string selectStmt = "SELECT BinaryData FROM ReportsGenerated WHERE FileBaseName = @fileBaseName"; string fbn = string.Format("deliveryperformance/{0}/{1}/{2}", unit, begindate, enddate); using (SqlConnection connection = new

memorystream copyto network stream issues

吃可爱长大的小学妹 提交于 2019-12-24 06:49:33
问题 I'm having a problem with this code here. using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms,SerializableClassOfDoom); ms.Position = 0; byte[] messsize = BitConverter.GetBytes(ms.Length); ms.Write(messsize, 0, messsize.Length); NetworkStream ns = Sock.GetStream(); ms.CopyTo(ns); //ms.Close(); } I can't figure out what's happening here, or why it's not working. It seems like eather it doesn't copy, or it closes the network stream, or

Properly Compressing a CSV utilizing GZIP Stream and Memory Stream

人盡茶涼 提交于 2019-12-24 03:22:37
问题 I am compressing a CSV file utilizing GZIPStream and MemoryStream, and noticing something weird with the result file. It seems like the CSV is not properly recognized. This shows when the file is attached to an email, but works fine when saved on a windows desktop. Here is the current snippet handling the gzip portion: GZipStream gStream = null; MemoryStream mStream = null; MemoryStream mStream2 = null; try { if (attachment.Length > 0) { mStream = new MemoryStream(); gStream = new GZipStream

C# Append PDF file to MemoryStream - Cannot access a closed Stream

早过忘川 提交于 2019-12-24 02:14:35
问题 Is it possible to append an existing PDF file to a dynamically created PDF using iTextSharp? I have attempted as per my code below using PdfCopy, but I am getting a Cannot access a closed Stream error. I've seen examples merging actual PDF files together, but I am not storing the finished PDFs, simply outputting the MemoryStream to a FilestreamResult: private readonly float _spacingBefore = 3f; private readonly float _spacingAfter = 3f; private readonly float _totalWidth = PageSize.A4.Width -

alternative to MemoryStream for large data volumes

五迷三道 提交于 2019-12-24 00:53:25
问题 I'm having problems with out of memory exceptions when using a .Net MemoryStream if the data is large and the process is 32 bit. I believe that the System.IO.Packaging API silently switches from memory to to file-backed storage as the data volume increases, and on the face of it, it seems it would be possible to implement a subclass of MemoryStream that does exactly the same thing. Does anyone know of such an implementation? I'm pretty sure there is nothing in the framework itself. 回答1:

MemoryStream from bytes array with different types of data

亡梦爱人 提交于 2019-12-23 16:34:06
问题 I want to create a memory stream which contains int32, int16, single values. Using binarywriter is useless so i tried to make bytes array. Because values are in different types, I don't know how to do it properly. So I try do like that: byte[] tab = new byte[]{2,0,0,0,3,0,3,0} - 2 is int32 (four bytes), another two 3 are int16 (two bytes) that works fine, but when i want to add some single values, it generates errors. I cant do like that : byte[] tab = new byte[]{2,0,0,0,3,0,3,0,4.4f,5.6f} I

Dispose MemoryStream when using with .Net Mail Attachment

这一生的挚爱 提交于 2019-12-23 10:16:12
问题 I am using a MemoryStream to add attachments from binary that is stored in a DB. My problem is that I want to properly dispose of the MemoryStream. This is easily done using a "using" statement, but when I have more than one attachment I don't know how to properly dispose of the multiple MemoryStreams. Is there a good way to iterate over and attach the files, but yet at the same time properly dispose of the MemoryStreams that I am using to attach? When I tried to flush/close prior to using

Web Api 2 - How to return an image (MemoryStream from Azure Storage) from a HTTPGET without saving to disk?

泪湿孤枕 提交于 2019-12-23 08:39:37
问题 I'm using Web Api 2 with C# and Azure, and having issues with how to return the image (base from Memorystream) for displaying on the page... Here is my Controller HTTPGET [Route("api/PhotoSubmit/GetPhoto/{id}")] [HttpGet] public HttpResponseMessage GetPhotoById(int id) { StorageServices storage = new StorageServices(); MemoryStream ms = storage.DownloadBlob(id); // return what ? } Here is the beginning of the servicecall : $http({ method: 'GET', url: 'api/PhotoSubmit/GetPhoto/' + $routeParams

When will MemoryStream.TryGetBuffer return a useful ArraySegment?

放肆的年华 提交于 2019-12-23 07:16:10
问题 bool MemoryStream.TryGetBuffer(out ArraySegment<byte> buffer) is a new API in .NET 4.6 that can be used to get access to the valid bytes stored in the MemoryStream without copying them. This is very exciting! It returns a bool that is "true if the conversion was successful; otherwise, false" and populates the out param. When does it return true, indicating that the out ArraySegment<byte> buffer now contains valid information? This isn't documented today. I know that if it returns false, I can