memorystream

What is the best practice for storing a file upload to a MemoryStream (C#) ?

I need to temporary store a file upload to a MemoryStream. What would be the best method to do this using asp.net (3.5)? Here's what I have so far. It works (locally tested), but it does not look right to me. protected void lnkUploadFile_Click(object sender, EventArgs e) { MemoryStream memStream = new MemoryStream(); BinaryWrit...

Why do these two files hash to the same value when I use MemoryStream?

Hello, I'm writing a c# routine that creates hashes from jpg files. If I pass in a byte array to my SHA512 object then I get the expected behavior, however, if I pass in a memory stream the two files always hash to the same value. Example 1: SHA512 mySHA512 = SHA512.Create(); Image img1 = Image.FromFile(@"d:\img1.jpg...

Overloaded signification on msdn

I don't understand what does the overloaded term mean in the context of msdn library's page for MemoryStream Close method (or others like Dispose). See the page here. To me, overloaded points out the fact that you are providing a method with the same name but different signature than an existing one AND in the same class. In this case,...

File Upload / Memory Stream Security

Hi, We are thinking of have a form on our webpage that would allow people to email attachments through. The method used to do this is via a memory stream, avoiding any files being written on to the actual server. Is anyone aware of any security risks / how to protect yourself against these? I would love to hear from you. Best regard...

Open "file" from memory stream?

Hi, I am wondering if its even possible. I am returning files from database (blob) and have them as bytes array. I would like to let the user to show the data content by clicking on associated object - something like opening in the WebBrowser which automatically selects the appropriate program..but I understand I would need to save the f...

MemoryStream.Position or MemoryStream.Seek does not work (Silverlight)

I have a memorystream in a silverlight app. I have to copy this memorystream to a filestream object. If I call: memoryStream.Position = 0; memoryStream.Seek(0,SeekOrigin.Begin); It does not work, I debug the application, check the properties of the memorystream, and the position still points to the end of the file. Any clues? ...

Sending an email attatchment increases the attatchments file size in .net

I am currently working a piece of code which needs to send an attachment in the email it generates. The attachment is a PDF document. Due to requirements I am unable to save the PDF and send it, so I have had to create a memory stream attachment. The issue I have with this is that the file size is _500KB. However save the file on my ma...

TCP Server and MemoryStreams/ByteArrays

I've got a TCP server written in C# that processes POST data sent to it. Currently it works fine unless a large amount of data (i.e. greater than 1GB) is sent to it then it runs out of memory (I store it all in memory as an array of bytes (with a intermediary of a List DTO)). For large files now I stream down to disk and then pass the fi...

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

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) } } Usage: char *mybuffer; size_t length; // ... allocate "mybuffer", put data into it, set "length" membuf mb(mybuffer, length); istream reader(&mb); // use "reader" I...

Sending large serialized objects over sockets is failing only when trying to grow the byte Array, but ok when using a massive byte array

I have code where I am trying to grow the byte array while receiving the data over my socket. This is erroring out. public bool ReceiveObject2(ref Object objRec, ref string sErrMsg) { try { byte[] buffer = new byte[1024]; byte[] byArrAll = new byte[0]; bool bAllBytesRead = fals...

Getting bad content in trailing section exception, when parsing xml produced by C# client in a GAEJ app

I am trying to POST a potentially large chunk of xml from a C# client to a GAEJ app, and then parse it into a DOM document. I've managed to get the documentbuilder to parse the xml by parsing the request data into a string and then trimming it, as such: String xml; BufferedReader rdr = req.getReader(); String ...

iTextSharp + FileStream = Corrupt PDF file

Hi, 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 sni...

XmlReader and MemoryStream, the returned xml misses tags

Could someone explain this behaviour to me? If you execute the snippet at the bottom of the post with the first string, it returns the exact same string as the one used for the input; that's what I expected. input 1: <?xml version='1.0' encoding='UTF-8'?> <Company> <Creator>Me</Creator> <CreationDateTime>2010-01-25T21:58:32.493</...

GZipStream, how correctly read from GZipStream

I have some code writen by me in C# string host = new Uri(_url).Host; IPHostEntry ipAddress = Dns.GetHostEntry(host); IPEndPoint ip = new IPEndPoint(ipAddress.AddressList[0], 80); using (Socket s = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { s.Connect(ip); ...

Name cannot begin with the ' ' character

I'm parsing some XML in C#. I'm getting it from a database, and so converting it to a MemoryStream before reading it with an XmlTextReader. The problem is that I get this error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3. Following is my XML and my code for reading it (it's coming out of the data...

Is it possible or even logical to download an executable from SQL server via .NET?

I am in the beginning stages of developing a solution to decrypt the hard drives of a few thousand laptops. I have a thought that it would be useful to create a parent application that would handle all of the database calls, client updates, client commands and status updates. This application would either run as a service or as a .EXE f...

Using MemoryStream to save .docx file C#

I've some trouble to upload file from Memory Stream to database (it's visible in DB as 0x so i guess it doesn't get saved properly). I am not sure whether it's a problem with Stream being created or save to db from stream should be done differently. private void test { byte[] storage = new byte[500000]; using (MemoryStre...

Saving file from SQL Server into Memory Stream in C#

I've method which saves the file saved in db into file on disk. How would I modify it so method returns MemoryStream? public static void databaseFileRead(string varID, string varPathToNewLocation) { using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetailsDZP)) using (var sqlQuery = new SqlC...

How can I modify an MSI in memory?

I'd like to read an MSI file into a MemoryStream (or something similar), and modify it. What's the easiest way to do this, without corrupting the MSI? All I need to be able to do is modify the value of one of the properties in the MSI. I'd prefer something in .Net, but I'm open to other platforms. Update: Here's my working code, using...

Reset or Clear .NET MemoryStream

The .NET MemoryStream does not appear to have a .Reset or .Clear method. I was thinking of using the following code to accomplish this: ms.Seek(0, IO.SeekOrigin.Begin) ms.SetLength(0) What is the proper way to clear or reset an existing .NET MemoryStream? ...