.NETGURU
MemoryStream Return Jibberish
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Scott Austin
Hello, I'm trying to use a MemoryStream in my application and am not
having any luck. Below is a simple example that reads a file, writes it
to a Memorystream and then writes it to another file. My objective is
not to copy a file but to use the memoryStream object, Im reading and
writing a file to illustrate this broken example. I greatly appreciate
any you can provide!

FileStream fs =3D new
FileStream(@"c:\del\officeview.jpg",FileMode.Open,FileAccess.Read);

byte[] buffer =3D new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();            =09

MemoryStream ms =3D new MemoryStream();
ms.Write(buffer,0,buffer.Length);
        =09
byte[] bufferFromMemory =3D new byte[ms.Length];
ms.Read(bufferFromMemory, 0, (int)ms.Length);
        =09
FileStream fsw =3D new
FileStream(@"c:\del\officeview1.jpg",FileMode.Create,FileAccess.Write);

fsw.Write(bufferFromMemory,0,bufferFromMemory.Length);
fsw.Close();

Reply to this message...
 
    
Brown, Telly
I think you have to reset to position of the memorystream to 0

-----Original Message-----
From: Scott Austin [mailto:Click here to reveal e-mail address]
Sent: Thursday, August 08, 2002 11:13 AM
To: aspngfreeforall
Subject: [aspngfreeforall] MemoryStream Return Jibberish

Hello, I'm trying to use a MemoryStream in my application and am not
having any luck. Below is a simple example that reads a file, writes it
to a Memorystream and then writes it to another file. My objective is
not to copy a file but to use the memoryStream object, Im reading and
writing a file to illustrate this broken example. I greatly appreciate
any you can provide!

FileStream fs = new
FileStream(@"c:\del\officeview.jpg",FileMode.Open,FileAccess.Read);

byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();                

MemoryStream ms = new MemoryStream();
ms.Write(buffer,0,buffer.Length);
            
byte[] bufferFromMemory = new byte[ms.Length];
ms.Read(bufferFromMemory, 0, (int)ms.Length);
            
FileStream fsw = new
FileStream(@"c:\del\officeview1.jpg",FileMode.Create,FileAccess.Write);

fsw.Write(bufferFromMemory,0,bufferFromMemory.Length);
fsw.Close();

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Yadav, Sanjeev (USPC.PCT.Hopewell)
I think you are missing ms.Position = 0
after ms.write

this should give you results.

-sanjeev

-----Original Message-----
From: Scott Austin [mailto:Click here to reveal e-mail address]
Sent: Thursday, August 08, 2002 12:13 PM
To: aspngfreeforall
Subject: [aspngfreeforall] MemoryStream Return Jibberish

Hello, I'm trying to use a MemoryStream in my application and am not
having any luck. Below is a simple example that reads a file, writes it
to a Memorystream and then writes it to another file. My objective is
not to copy a file but to use the memoryStream object, Im reading and
writing a file to illustrate this broken example. I greatly appreciate
any you can provide!

FileStream fs = new
FileStream(@"c:\del\officeview.jpg",FileMode.Open,FileAccess.Read);

byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();                

MemoryStream ms = new MemoryStream();
ms.Write(buffer,0,buffer.Length);
            
byte[] bufferFromMemory = new byte[ms.Length];
ms.Read(bufferFromMemory, 0, (int)ms.Length);
            
FileStream fsw = new
FileStream(@"c:\del\officeview1.jpg",FileMode.Create,FileAccess.Write);

fsw.Write(bufferFromMemory,0,bufferFromMemory.Length);
fsw.Close();

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
 
System.IO.FileAccess
System.IO.FileMode
System.IO.FileStream
System.IO.MemoryStream




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification