Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 22, 2006 6:14 PM
Hi
I receive files as byte array from a Web service along with the enconding for the same. I want to write the byte array into a file in the local system and I would like to write the file in the same encoding that I recieived from the service.
I tried FileStream to write into the local file system, but I don't find any options to specify the encoding.
Please let me know how to acheive this. I'm using .NET 1.1
Thanks in advance,
Karthick.
All replies (4)
Wednesday, August 23, 2006 5:57 AM âś…Answered | 1 vote
yes
filestream read or write primative types (byte array), you will need a streamReader or streamWiter to turn it to human readable data , to do that you have to know the encoding , and you can let the streamReader to detect the encoding from the byte array
FileStream fs = new FileStream("<path>");
StreamReader sr = new StreamReader(fs);
System.Text.Encoding code = sr.CurrentEncoding;
StreamWriter sw = new StreamWriter(fs, code);
hope this helps
Tuesday, August 22, 2006 8:10 PM
hi,
you can use streamreader and streamwriter to read from a stream, you can set the default incoding or you can set a bool value to detict the default incoding
FileStream fs = new FileStream("");
StreamReader sr= new StreamReader(fs, true);
StreamWriter sw = new StreamWriter(fs, true);
you can also use sr , sw to read directly from networkstream
hope this helps
Wednesday, August 23, 2006 4:50 AM
I would be receiving file byte array and encoding string as attributes in a complex type from the Webservice. These will be deserialized into an object with these two attributes.
I need to convert this byte array into a physical file using the encoding string which I received.
Hope I have cleared my requirment.
Thursday, August 24, 2006 7:04 PM
Thanks a lot.
This solves my problem.