memorystream

Getting PdfStamper to work with MemoryStreams (c#, itextsharp)

天涯浪子 提交于 2019-11-26 21:28:32
问题 It came to me to rework old code which signs PDF files into new one, which signs MemoryStreams (byte arrays) that come and are sent by web services. Simple, right? Well, that was yesterday. Today I just can't get it to work. This is the old code, which uses FileStreams and it works: public static string OldPdfSigner(PdfReader pdfReader, string destination, string password, string reason, string location, string pathToPfx) { using (FileStream pfxFile = new FileStream(pathToPfx, FileMode.Open,

iTextSharp + FileStream = Corrupt PDF file

你离开我真会死。 提交于 2019-11-26 20:44:09
问题 I am trying to create a pdf file with iTextSharp. My attempt writes the content of the pdf to a MemoryStream so I can write the result both into file and a database BLOB. The file gets created, has a size of about 21kB and it looks like a pdf when opend with Notepad++. But my PDF viewer says it's currupted. Here is a little code snippet (only tries to write to a file, not to a database): Document myDocument = new Document(); MemoryStream myMemoryStream = new MemoryStream(); PdfWriter

Copy MemoryStream to FileStream and save the file?

白昼怎懂夜的黑 提交于 2019-11-26 17:45:23
问题 I don't understand what I'm doing wrong here. I generate couple of memory streams and in debug-mode I see that they are populated. But when I try to copy MemoryStream to FileStream in order to save the file fileStream is not populated and file is 0bytes long (empty). Here is my code if (file.ContentLength > 0) { var bytes = ImageUploader.FilestreamToBytes(file); // bytes is populated using (var inStream = new MemoryStream(bytes)) // inStream is populated { using (var outStream = new

How to bind a MemoryStream to asp:image control?

我们两清 提交于 2019-11-26 16:33:25
Is there a way to bind a MemoryStream to asp:image control? Joel Coehoorn A handler can accept a url parameter like any other request. So instead of linking your <asp:image/> to image.ashx you'd set it to image.ashx?ImageID=[Your image ID here] . Best bet is to create an HttpHandler that would return the image. Then bind the ImageUrl property on the asp:Image to the url of the HttpHandler. Here is some code. First create the HttpHandler: <%@ WebHandler Language="C#" Class="ImageHandler" %> using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web; public class

Creating WPF BitmapImage from MemoryStream png, gif

删除回忆录丶 提交于 2019-11-26 16:25:47
I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if (stream.CanRead) { Byte[] buffer = new Byte[webResponse.ContentLength]; stream.Read(buffer, 0, buffer

How to get a MemoryStream from a Stream in .NET?

旧城冷巷雨未停 提交于 2019-11-26 15:51:37
问题 I have the following constructor method which opens a MemoryStream from a file path: MemoryStream _ms; public MyClass(string filePath) { byte[] docBytes = File.ReadAllBytes(filePath); _ms = new MemoryStream(); _ms.Write(docBytes, 0, docBytes.Length); } I need to change this to accept a Stream instead of a file path. Whats the easiest/most efficient way to get a MemoryStream from the Stream object? 回答1: If you're modifying your class to accept a Stream instead of a filename, don't bother

Error“ Parameter is not valid ” while converting Bytes into Image

妖精的绣舞 提交于 2019-11-26 14:45:32
问题 I am converting bytes into an image but I get an error Parameter is not valid I am pasting my code. Kindly check the code and suggested that was I am doing right or wrong. Image arr1 = byteArrayToImage(Bytess); This is the function. public static Image byteArrayToImage(byte[] byteArrayIn) { if (null == byteArrayIn || byteArrayIn.Length == 0) return null; MemoryStream ms = new MemoryStream(byteArrayIn); try { Process currentProcess1 = Process.GetCurrentProcess(); Image returnImage = Image

How do you get a string from a MemoryStream?

ぐ巨炮叔叔 提交于 2019-11-26 14:02:29
If I am given a MemoryStream that I know has been populated with a String , how do I get a String back out? Brian This sample shows how to read and write a string to a MemoryStream. Imports System.IO Module Module1 Sub Main() ' We don't need to dispose any of the MemoryStream ' because it is a managed object. However, just for ' good practice, we'll close the MemoryStream. Using ms As New MemoryStream Dim sw As New StreamWriter(ms) sw.WriteLine("Hello World") ' The string is currently stored in the ' StreamWriters buffer. Flushing the stream will ' force the string into the MemoryStream. sw

Simpler way to create a C++ memorystream from (char*, size_t), without copying the data?

折月煮酒 提交于 2019-11-26 13:03:10
问题 I couldn\'t find anything ready-made, so I came up with: class membuf : public basic_streambuf<char> { public: membuf(char* p, size_t n) { setg(p, p, p + n); setp(p, p + n); } } Usage: char *mybuffer; size_t length; // ... allocate \"mybuffer\", put data into it, set \"length\" membuf mb(mybuffer, length); istream reader(&mb); // use \"reader\" I know of stringstream , but it doesn\'t seem to be able to work with binary data of given length. Am I inventing my own wheel here? EDIT It must not

Attach a file from MemoryStream to a MailMessage in C#

旧城冷巷雨未停 提交于 2019-11-26 11:14:11
I am writing a program to attach a file to email. Currently I am saving file using FileStream into disk, and then I use System.Net.Mail.MailMessage.Attachments.Add( new System.Net.Mail.Attachment("file name")); I do not want to store file in disk, I want to store file in memory and from memory stream pass this to Attachment . Waqas Raja Here is the sample code. System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.IO.StreamWriter writer = new System.IO.StreamWriter(ms); writer.Write("Hello its my sample file"); writer.Flush(); writer.Dispose(); ms.Position = 0; System.Net.Mime