0

I have:

WebClient cl = new WebClient();
NameValueCollection nvm = new NameValueCollection();

nvm["name"] = data.Name;
nvm["description"] = data.Description;
nvm["file"] = // File.OpenRead(data.FilePath) ? or how send file content ?

cl.UploadValues("https://database.org/upload.php", "POST", nvm);

My question is: how to send file ? Using stream ? or how ?

Clemens
  • 123,504
  • 12
  • 155
  • 268
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
  • if your file is a text file, just paste the content. If not, you can always get bytes from the file and send the array (take a look at [this](https://stackoverflow.com/questions/2030847/best-way-to-read-a-large-file-into-a-byte-array-in-c)) – Krzysztof Skowronek Jun 04 '18 at 10:05

1 Answers1

0

UploadValues uploads a NameValueCollection. If you wish yo upload a file use UploadFile(uri, "POST", pathToFile) instead, or serialize to base64 your file content.

PepitoSh
  • 1,774
  • 14
  • 13
  • You didn't read my title... I want to upload file and form values ... not only file – Snake Eyes Jun 04 '18 at 10:00
  • You didn't read my answer. :) UploadValues will not upload files for you *as files*, only values. Convert your file to a value that NVM can handle. Or use a different method. – PepitoSh Jun 04 '18 at 10:05