S
Scott, Killer of all Ninjas
It seems incredulous to me that it is so difficult to write the
contents of a memory stream to a file. I'm certain that I'm missing
something simple.
I am retrieving a memory stream from a DIME attachment:
MyDimeService svc = new MyDimeService();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
System.IO.Stream dimeStream =
svc.ResponseSoapContext.Attachments[0].Stream;
SaveStreamToFile(ref dimeStream);
}
In SaveStreamToFile I'm simply attempting to write the stream to a
file similar to the way it's done in the MSDN help:
private void SaveStreamToFile(ref System.IO.Stream pStreamToSave)
{
System.IO.FileStream fs = new
System.IO.FileStream(@"c:\images\new\new.gif",
System.IO.FileMode.Create);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
for (int i=0; i<=pStreamToSave.Length; i++)
{
bw.Write(pStreamToSave.ReadByte());
}
bw.Close();
fs.Close();
}
Unfortunately, my file ends up four times the size of the original.
There has to be some standard method of creating a binary file from a
stream.
I've looked through the newsgroups and really haven't found anything
other than the method I'm doing.
Any help would be greatly appreciated.
Thanks...
contents of a memory stream to a file. I'm certain that I'm missing
something simple.
I am retrieving a memory stream from a DIME attachment:
MyDimeService svc = new MyDimeService();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
System.IO.Stream dimeStream =
svc.ResponseSoapContext.Attachments[0].Stream;
SaveStreamToFile(ref dimeStream);
}
In SaveStreamToFile I'm simply attempting to write the stream to a
file similar to the way it's done in the MSDN help:
private void SaveStreamToFile(ref System.IO.Stream pStreamToSave)
{
System.IO.FileStream fs = new
System.IO.FileStream(@"c:\images\new\new.gif",
System.IO.FileMode.Create);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
for (int i=0; i<=pStreamToSave.Length; i++)
{
bw.Write(pStreamToSave.ReadByte());
}
bw.Close();
fs.Close();
}
Unfortunately, my file ends up four times the size of the original.
There has to be some standard method of creating a binary file from a
stream.
I've looked through the newsgroups and really haven't found anything
other than the method I'm doing.
Any help would be greatly appreciated.
Thanks...