memorystream

Unexpected end of MIME multipart stream in reading the second time in Web API

我与影子孤独终老i 提交于 2019-12-08 07:39:10
问题 at first step I tried to read the contents into MultipartMemoryStreamProvider with the following code var multipartMemoryStreamProvider = await Request.Content.ReadAsMultipartAsync(); It solve my problem in getting the input File in memory.In this case I have access to other contents Key , but not value . I tried to get them with reading again the Contents into MultipartFormDataStreamProvider variable string root = HttpContext.Current.Server.MapPath("~/uploads"); var provider = new

.net Core Mailkit send attachement from array

…衆ロ難τιáo~ 提交于 2019-12-08 07:16:42
问题 I am testing .Net Core MVC, which does not support System.Net.Mail, the only alternative I found is Mailkit, works well but can't figure out how to send attachments that I have stored in my database as binary. I used the following in MVC 5: var mail = new MailMessage(); mail.Attachments.Add(new Attachment(new MemoryStream(attachment), attachmentName, attachmentType)); How can I do it in MailKit. 回答1: You need to create a builder and then add the attachments to it, the attachments can be

having issue with attaching the PDF file from memory stream using ITextSharp

我只是一个虾纸丫 提交于 2019-12-07 19:17:09
问题 I am having problem with attaching the PDF file created in-memory and attaching it to email template. email goes without any problem..BUT there is no attachment. I don't understand why this is happening. here is the complete code for the process. ExtendedEmailTemplate emailTemp = new ExtendedEmailTemplate(); emailTemp.FromAddress = "ABC Ltd <info@abcTechnology.com>"; emailTemp.ToAddress = custEmail; emailTemp.Body = "This is an Test Email" emailTemp.IsHTML = true; // getting the memorystream

create file and save to it using memorystream

一曲冷凌霜 提交于 2019-12-07 15:22:13
问题 How can i create a file and write to it using the memory stream? I need to use the memorystream to prevent other threads from trying to access the file. The data i'm trying to save to a file is html. How can this be done? 回答1: (Presuming you mean how to copy a file's content to a memory stream) If you are using framework 4: MemoryStream memoryStream = new MemoryStream(); using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { fileStream.CopyTo(memoryStream);

how to convert Image to string the most efficient way?

元气小坏坏 提交于 2019-12-07 14:14:41
问题 I want to convert an image file to a string. The following works: MemoryStream ms = new MemoryStream(); Image1.Save(ms, ImageFormat.Jpeg); byte[] picture = ms.ToArray(); string formmattedPic = Convert.ToBase64String(picture); However, when saving this to a XmlWriter, it takes ages before it's saved(20secs for a 26k image file). Is there a way to speed this action up? Thanks, Raks 回答1: There are three points where you are doing large operations needlessly: Getting the stream's bytes Converting

different thread accessing MemoryStream

笑着哭i 提交于 2019-12-07 04:45:21
问题 There's a bit of code which writes data to a MemoryStream object directly into it's data buffer by calling GetBuffer(). It also uses and updates the Position and SetLength() properties appropriately. This code works properly 99.9999% of the time. Literally. Only every so many 100,000's of iterations it will barf. The specific problem is that the Position property of MemoryStream suddenly returns zero instead of the appropriate value. However, code was added that checks for the 0 and throws an

How to remove data from a MemoryStream

穿精又带淫゛_ 提交于 2019-12-07 03:23:53
问题 I cannot get this to work. I have a MemoryStream object. This class has a Position property that tells you how many bytes you have read. What I want to do is to delete all the bytes between 0 and Position-1 I tried this: MemoryStream ms = ... ms.SetLength(ms.Length - ms.Position); but at some point my data gets corrupted. So I ended up doing this MemoryStream ms = ... byte[] rest = new byte[ms.Length - ms.Position]; ms.Read(rest, 0, (int)(ms.Length - ms.Position)); ms.Dispose(); ms = new

how to convert created excel file using closed xml into bytes format

只谈情不闲聊 提交于 2019-12-07 01:53:33
Hi I am using closedxML DLL for exporting to excel i have static method like this below public static void WriteToExcel(string fileName, List<CP> pages) { var wb = new XLWorkbook(); byte[] file; var ws = wb.Worksheets.Add("CPs"); WriteCostHeader(ws); ////write all the header columns //for (int i = 0; i < pages.Count; i++) int iRow = 2; foreach(var page in pages) { WriteCostPage(ws, page, iRow++); WriteCostItemHead(ws, iRow++); foreach(var item in page.Items) { WriteCostItem(ws, item, iRow++); } iRow++; } wb.SaveAs(fileName); } I am calling above function in a method like this below public

MemoryStream.WriteTo(Stream destinationStream) versus Stream.CopyTo(Stream destinationStream)

天涯浪子 提交于 2019-12-06 23:21:38
问题 Which one is better : MemoryStream.WriteTo(Stream destinationStream) or Stream.CopyTo(Stream destinationStream) ?? I am talking about the comparison of these two methods without Buffer as I am doing like this : Stream str = File.Open("SomeFile.file"); MemoryStream mstr = new MemoryStream(File.ReadAllBytes("SomeFile.file")); using(var Ms = File.Create("NewFile.file", 8 * 1024)) { str.CopyTo(Ms) or mstr.WriteTo(Ms);// Which one will be better?? } Update Here is what I want to Do : Open File [

How to merge two memory streams?

孤者浪人 提交于 2019-12-06 22:14:05
问题 I have two MemoryStream instances. How to merge them into one instance? Well, now I can't copy from one MemoryStream to another. Here is a method: public static Stream ZipFiles(IEnumerable<FileToZip> filesToZip) { ZipStorer storer = null; MemoryStream result = null; try { MemoryStream memory = new MemoryStream(1024); storer = ZipStorer.Create(memory, GetDateTimeInRuFormat()); foreach (var currentFilePath in filesToZip) { string fileName = Path.GetFileName(currentFilePath.FullPath); storer