memorystream

I'm Trying to Create an Image Object with a Byte Array as Its Source. What Am I Doing Wrong?

I'm trying to create an image object with a byte array as its source. What am I doing wrong? An exception is thrown when I try to initialize the image object with an array of bytes as source data. The exception is shown in my code, below. public class MyClass { publuc System.Windows.Media.Imaging.BitmapImage InstanceImage { get...

How to run unmanaged executable from memory rather than disc

I want to embed a command-line utility in my C# application, so that I can grab its bytes as an array and run the executable without ever saving it to disk as a separate file (avoids storing executable as separate file and avoids needing ability to write temporary files anywhere). I cannot find a method to run an executable from just it...

Equivalent of Java's "ByteBuffer.putType()" in C#

Hello :) I am trying to format a byte array in C#, by porting a code from Java. In Java, the methods "buf.putInt(value);", buf.putShort, buf.putDouble, (and so forth) are used. However I don't know how to port this to C#. I have tried the MemoryStream class, but there is no method to put a specific type at the end of the byte array. Qu...

What is the equivalent of "ByteBuffer.flip" & "ByteBuffer.slice" in .NET?

Hello :) I need to port code from Java to C#. In the Java code, the methods "ByteBuffer.flip()" and "ByteBuffer.slice" is used, and I don't know how to translate this. I've read this question (http://stackoverflow.com/questions/607587/an-equivalent-of-javax-nio-buffer-flip-in-c), but although an answer is given, I cannot figure how to ...

.Net MemoryStream close issue

Hello everyone, For a .Net MemoryStream object instance, do I need to close it explicitly after using it? Or no need to close it? Which is the best practices? I am using VSTS2008 + .Net 3.5 + C#. thanks in advance, George ...

c# execute program from MemoryStream

Hi maestros, How can I execute a program that is in a MemoryStream so I don't have to save it first to the harddisk. The file may not be saved temperally to the harddisk. The program has to be 100% functional from in memory. static string strTemplate = "MyAPP.SOMEprogram.exe"; byte[] template; int len = 0; ...

C# 3.0 Save itextsharp pdf to database using MemoryStream

Hi! I'm trying to save to databse a pdf file generated by itextsharp. But, I haven't been successfully so far. I'm using Linq to sql. Here's the code: MemoryStream ms = new MemoryStream(); Document d = new Document(PageSize.A4, 60, 60, 40, 40); PdfWriter w = PdfWriter.GetInstance(d, ms); ...

How do I send a PDF in a MemoryStream to the printer in .Net?

I have a PDF created in memory using iTextSharp and contained in a MemoryStream. I now need to translate that MemoryStream PDF into something the printer understands. I've used Report Server in the past to render the pages to the printer format but I cant use it for this project. Is there a native .Net way of doing this? For example, G...

C# to Java: Base64String, MemoryStream, GZipStream

I have a Base64 string that's been gzipped in .NET and I would like to convert it back into a string in Java. I'm looking for some Java equivalents to the C# syntax, particularly: Convert.FromBase64String MemoryStream GZipStream Here's the method I'd like to convert: public static string Decompress(string zipText) { byte[] gzipB...

precautions for reading from a memorystream in c#

Hey guys I recently came across this web page http://www.yoda.arachsys.com/csharp/readbinary.html explaining what precautions to take when reading from a filestream. The gist of it is that the following code doesnt always work: // Bad code! Do not use! FileStream fs = File.OpenRead(filename); byte[] data = new byte[fs.Length]; fs.Read (...

SevenZip, many trailing 0s

My array is 140bytes. outArray is 512bytes... Not what i wanted. Also i dont know if i am encrypting properly. Is the code below correct? how do i fix this so outArray is the real size and not fixed with many trailing zeros? var compress = new SevenZipCompressor(); compress.CompressionLevel = CompressionLevel.Ultra; ...

Is there an in memory stream that blocks like a file stream

I'm using a library that requires I provide an object that implements this interface: public interface IConsole { TextWriter StandardInput { get; } TextReader StandardOutput { get; } TextReader StandardError { get; } } The object's readers then get used by the library with: IConsole console = new MyConsole(); int readByte...

Removing data from memory stream

Hi i am new to c#. I am trying to understand the usage of .Net MemoryStream class. I need to use the store some temporary dynamic length binary data as the stream is busy. So i allocate a memory stream and temporarily write that data to it. When my stream gets free i read all the data from the memorystream and write the data to it. I do ...

Will a large System.IO.MemoryStream result in my application's memory usage increasing dramatically?

I am building a library that allows a user to download files from a URL. One of the options I am considering is letting the user specify the expected MD5 checksum for the file; the library's GetFile(string url) function ensures that the checksum for the downloaded stream matches the one specified by the user. Being aware that the Networ...

Search and Replace of text in a memorystream in C# .NET

I have loaded a memorystream with a word document and I want to be able to alter specific text within the memorystream and save it back to the word document, like search and replace functionality. Please can anyone help me with this as I don't want to use the Word Interop libraries. I have the code to load and save the document already...

C# UDP decoding datagrams fails randomly

Hi, I'm experiencing an issue in a multi threaded application and have been debugging it for the last 3 days but for the life of it can not figure it out. I'm writing this, hoping that I either have a DUH moment when typing this or somebody sees something obvious in the code snippets I provide. Here's what's going on: I've been working...

How to simplify this MemoryStream code

This code returns a thumbnail of an image loaded from a byte array. I'm trying to understand why the author is using 4 memory streams and if there is a simple way of rewriting this or if it is okay the way it is. public Image GetThumbnail(int height, int width) { //load the image from a byte array (imageData) using (MemoryStream...

How do I "fork" a Stream in .NET?

As discussed before, when a BinaryReader or BinaryWriter gets closed, its underlying Stream get closed as well (aargh). Consider this situation: a routine R is passed a MemoryStream, say M; I would like to write some stuff to M and then pass it to another routine for more processing (not necessarily writing). For convenience, I'd like t...

Why does MemoryStream.GetBuffer() always throw?

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 ...

Save uploaded file to MemoryStream

Hi! How can I save a uploaded file (a pdf for example) to a MemoryStream? Thanks!! ...