Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com