issue regarding encoding

G

Guest

hello all,

I am using vb.net to read a image file and then tryied to convert it to a
string using the following code

Dim fs As FileStream = New FileStream(filename,
FileMode.OpenOrCreate, FileAccess.Read)
Dim rawData() As Byte = New Byte(fs.Length) {}
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length))
fs.Close()

dim filedata as string
filedata=System.Text.ASCIIEncoding.ASCII.GetString(rawData)

Upto this point it get converted into string

Now I am passing this string to some web service where i want to get the
image back from this string

I write my code like this

Dim bw As BinaryWriter
Dim outbuff() As Byte
outbuff =
System.Text.ASCIIEncoding.ASCII.GetBytes(filedata )
fs = New FileStream("C:\" & nodeattrib.Value,
FileMode.Create, FileAccess.Write)
fs.Write(outbuff, 0, outbuff.Length)

File is created in the path specified but, i cannot open it.

Can Anyone help me out in this case.

It is very urgent

Thanks in advance
 
M

m.posseth

when you want to sent Binary files like that over the wire , you would
better encode base 64 the binarry , send it over and decode base 64 the
string to binarry

this worked perfectly in my projects

hth

Michel Posseth [MCP]
 
H

Herfried K. Wagner [MVP]

m.posseth said:
when you want to sent Binary files like that over the wire , you would
better encode base 64 the binarry , send it over and decode base 64 the
string to binarry

ACK. You can use 'Convert.ToBase64*' and 'Convert.FromBase64*' for this
purpose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top