I'm uploading an image, and i need to store it with the rest of the requested content by the server.

so right now im using

streamreader getimg = new streamreader(imagepath);
string image = getimg.readtoend();
getimg.close();

string DataToBeUploaded = "requested content..." + image + "more requested content";

Everything is working, but the pixels in the picture get mixed up by the time it gets to the server (heres an example: http://img35.imageshack.us/img35/7844/taskmngr.png )

I was thinking i had to use some special encoding for images when saving it as a string?

Recommended Answers

All 9 Replies

Use Convert.ToBase64String method.

tryed that, the server doesnt decode it.

Why are you attempting to store binary in a string? Use a byte[] array and what are the classes you're using.

Also please post these question to the ASP.NET forum in the future :)

I need to send this to the request stream:

"text content"
image content
"more text content"

I just can't seem to get the encoding right to get the image from the file to request stream.

this is what it looks like at the server:

[img]http://img40.imageshack.us/img40/2565/taskmngrh.png[/img]

sknake im using HttpWebRequest class

Screen shots are irrelevant. What are you trying to do? Send and receive text & binary data in C#/ASP.NET?

yes im trying to send text with an image through a stream, and i cant figure out how to send it

Create an envelope or use two separate streams. IE you could create a class that holds a string and a byte[] array, serialize it, and send it across the pipe. You will probably want to base64Encode the binary data to serialize it.

Sending a string then binary data in a single stream is ill advised. It makes life hard for no reason.

Solved after 4 days of trial and error.

I just used a memorystream

thanks for trying though, i know i wasn't very descriptive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.