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...
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...
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...
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 ...
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
...
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;
...
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);
...
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...
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...
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 (...
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;
...
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...
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 ...
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...
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...
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...
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...
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...
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 ...
Hi!
How can I save a uploaded file (a pdf for example) to a MemoryStream?
Thanks!!
...