File upload to zoho contacts in C#.Net

I'm trying to upload attachments to Zoho CRM contacts using RestSharp but not able to do it. Every time I get response "Bad Request: the request doesn't contain any file". I'm able to upload files to zoho crm contacts using postman but no success through C#.Net application.

I'm using the following code for my C#.Net application. Can you please guide me what wrong I'm doing.

var client = new RestClient("{contactID}/Attachments");
var request = new RestRequest(Method.POST);
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Authorization", "Zoho-oauthtoken <access-token>");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------`enter code here`WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; path=\"E:\\10.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Thanks in advance.

- - Source
comments powered by Disqus