开发者

How to modify Content-Disposition Header when using .net WebClient FileUpload

开发者 https://www.devze.com 2023-02-13 12:28 出处:网络
Is it possible to manually set the name attribute in the multipart header when using .net WebClient UploadFile? Or is there another way to get this solved?

Is it possible to manually set the name attribute in the multipart header when using .net WebClient UploadFile? Or is there another way to get this solved?

-----------------------8cda1896efcd67f
Content-Disposition: form-data; **name="file"**; 开发者_C百科filename="Testfile.txt"
Content-Type: application/octet-stream

This is a Testfile.
-----------------------8cda1896efcd67f--

Thanks for any suggestions!


You can use the MultipartFormDataContent in the following way:

MultipartFormDataContent form = new MultipartFormDataContent();
string filename = @"Dir:\Testfile.txt"       
    , name = "file";
byte[] bytes = System.IO.File.ReadAllBytes(filename);

form.Add(new StringContent(name), "file");
form.Add(new ByteArrayContent(bytes), "File", Path.GetFileName(filename));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号