Hello, I'm trying to upload a file to a server with VB .NET. I can't figure out what to do to read the file to put in the post data.

I have the rest of my code set up, and here is my post data setting:

Dim data As String = "description=none&file_type=image&dimension=Default&the_file=" & FILE & "&UPLOAD_IDENTIFIER=576136393_1264811252&upk=075be15511b10c2debc629dc7f3c0664&domain_leng=en&action=upload&MAX_FILE_SIZE=500000000&shareopt=true"

As you see, I have & FILE & where my file should be. I can't just put a string there.

I wrote a similar script in python, and you would put something like "open("file", "rb")" rb being the setting readbytes.... I can't figure out how to imulatre this in VB .NET. Thank you for any help.

>what to do to read the file to put in the post data.

You should use System.IO.File class method.

Dim byts() as byte=System.IO.File.ReadAllBytes("filename")

>what to do to read the file to put in the post data.

You should use System.IO.File class method.

Dim byts() as byte=System.IO.File.ReadAllBytes("filename")

How would I add it to the post data string, though? That's what I can't figure out. =(

>How would I add it to the post data string?

Text encoding method,

Dim str As String  = System.Text.Encoding.Unicode.GetString(byts)

Thanks, I tried that but it always says that the set content length isn't the right size, even though I set it to my data string's length. Any help?

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.