memorystream

Excel and “unreadable content” when creating an Open XML spreadsheet with MemoryStream

谁说我不能喝 提交于 2019-12-12 08:27:15
问题 When creating an Excel spreadsheet using the Open XML SDK v2.0, our Excel output initially worked successfully for a number of months. Recently Excel (all versions) began to complain about "Excel found unreadable content in 'zot.xlsx'. Do you want to recover the contents of this workbook?". We are creating the file in a web application, using a MemoryStream as the store, which is then sent as a byte[] in an HTTP response with a MIME type of "application/vnd.openxmlformats-officedocument

Download blob storage and return Json object

大憨熊 提交于 2019-12-12 08:10:48
问题 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

Quick way to get the contents of a MemoryStream as an ASCII string

試著忘記壹切 提交于 2019-12-12 07:47:18
问题 I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string: MemoryStream memstream = new MemoryStream(); /* Write a JSON string to memstream here */ byte[] jsonBytes = new byte[memstream.Length]; memstream.Read(jsonBytes, 0, (int)memstream.Length); string jsonString = Encoding.ASCII.GetString(jsonBytes); What is a shorter/shortest way to do this? 回答1: You could use the ToArray method: using (var stream = new MemoryStream()) { /* Write a JSON string

How to download memorystream to a file?

我与影子孤独终老i 提交于 2019-12-12 07:14:43
问题 I'm using the below sample code for writing and downloading a memory stream to a file in C#. MemoryStream memoryStream = new MemoryStream(); TextWriter textWriter = new StreamWriter(memoryStream); textWriter.WriteLine("Something"); byte[] bytesInStream = new byte[memoryStream.Length]; memoryStream.Write(bytesInStream, 0, bytesInStream.Length); memoryStream.Close(); Response.Clear(); Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment;

How to increase the capacity in Memory Stream?

这一生的挚爱 提交于 2019-12-12 07:05:09
问题 I am using MemoryStream to store a report. But the MemoryStream won't store the report if the size of the report is more than 70000. So I should increase the size of the MemoryStream in that case. How can I increase the size of the MemoryStream? say for example, mstream=new MemoryStream(); stream.copyTo(mstream); // Here stream contains the report mstream.position=0; In this case how can I increase the capacity of MemoryStream so that it can store even if the report size is more than 7000.

Encrypt to memory stream, pass it to file stream

淺唱寂寞╮ 提交于 2019-12-12 04:56:29
问题 Based on this code: static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV) { // Check arguments. if (plainText == null || plainText.Length <= 0) throw new ArgumentNullException("plainText"); if (Key == null || Key.Length <= 0) throw new ArgumentNullException("Key"); if (IV == null || IV.Length <= 0) throw new ArgumentNullException("Key"); byte[] encrypted; // Create an Rijndael object // with the specified key and IV. using (Rijndael rijAlg = Rijndael.Create()) { rijAlg

Trying to use PdfStamper and MemoryStream to add data to existing PDF then email it

﹥>﹥吖頭↗ 提交于 2019-12-12 03:38:40
问题 Here is my chunk of code. It compiles fine and when I fire off the event I get the email, but I then get this error Email attachment ERROR on Adobe while opening(Acrobat could not open 'Att00002.pdf' because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasnt correctly decoded.) string agentName = "My Name"; MemoryStream _output = new MemoryStream(); PdfReader reader = new PdfReader("/pdf/Agent/Specialist

Programmatically Attach PDF from MemoryStream to Outlook E-Mail Items

为君一笑 提交于 2019-12-12 03:37:27
问题 Would it be possible to attach PDF from MemoryStream or other functions to Outlook E-Mail Items MailItem.Attachment.add() , rather than from the file on the hard disk by passing the physical path of file in this method. I would like to create the Outlook mailitem for the users with the PDF attached programmatically, and let the users to review and send out the email by themselves. Thank you in advance. 回答1: Not using the Outlook Object Model - Attachments.Add will only let you pass a file

Why does breaking out of a foreach loop cause complaint “Cannot access a closed Stream”?

那年仲夏 提交于 2019-12-12 03:06:26
问题 Based on the suggestion in the comments here, I refactored my method to try to assign data to a MemoryStream outside of the iTextSharp.text.Document "using" (but within the MemoryStream using clause): internal static HttpResponseMessage GeneratePDFOfReportFutures() { HttpResponseMessage result = null; futureReports = GetAllFutureReports(); try { using (var ms = new MemoryStream()) { using (var doc = new Document(PageSize.A4.Rotate(), 25, 25, 25, 25)) // the "Rotate" makes it landscape

MVC3 + Streaming images from the Database is causing very high CPU usage on my server

走远了吗. 提交于 2019-12-11 19:48:53
问题 I have this site that streams images from the database (SQL2008), and I think it's the one causing the very high CPU usage on my server. The CPU usage is at least 60-90%. I am using MVC3 and below is the code in my Controller that sends the image to the View: [OutputCache(Duration = 86400, VaryByParam = "GUID")] public FileStreamResult GetFile(string guid) { Guid id = new Guid(guid); Thumbnail thumbnail = thumbService.GetThumbnailByGUID(id); Stream stream = new MemoryStream(thumbnail