title: Upload File using RestClient as multipart/form-data in c#
body: <p>I am trying to upload files from the c# class using <strong>restClient</strong> (RestSharp) request.
  I am creating Method.POST method and add one Audio file to this request As multipart/form-data. </p>
  
  <p>Server throws an exception when I execute the request.</p>
  
  <p>Exception : </p>
  
  <pre><code> System.ArgumentNullException: Value cannot be null.
   Parameter name: value
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult&amp; parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at Groove.Libraries.Helper.EnumHelper.ParseEnum[T](String value) in D:\project\Groove\Web\Groove\Libraries\Helper\EnumHelper.cs:line 47
   at Groove.Controllers.Api.DocumentController. 
   &lt;PostDocumentUpload&gt;d__5.MoveNext()
  </code></pre>
  
  <p>RestClient Request Code :</p>
  
  <pre><code>string api_url = "http://localhost:57997/";
  var fullFileName = "Adios.mp3";
  var filepath = @"C:\Users\Admin\Desktop\Adios.mp3";
  
  RestClient client = new RestClient(ApiModel.api_url);
  
  var request = new RestRequest("api/document", Method.POST);
  request.AddFile(Path.GetFileNameWithoutExtension(fullFileName), filepath);
  request.AddHeader("Content-Type", "multipart/form-data");
  request.AddParameter("ReferenceType",28,ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  </code></pre>
  
  <p>Server Code : </p>
  
  <pre><code>public async Task&lt;object&gt; PostDocumentUpload()
      {
          try
          {
              // Make temp physical path where file to be saved
              var tempPath =
                  HttpContext.Current.Server.MapPath(string.Format("{0}/{1}", Constants.MediaResourceFolder,
                      Constants.MediaResorceTempFolder));
  
              // Check temporary path is exist or not, if not then create temporary folder
              if (!Directory.Exists(tempPath))
              {
                  Directory.CreateDirectory(tempPath);
              }
  
              // Create object of MyMultipartFormDataStreamProvider class
              var stream = new MultipartHelper(tempPath);
  
              // Save file at temp path
              await RequestContext.Request.Content.ReadAsMultipartAsync(stream);
  
              // Exception throw from Here,
              ReferenceType referenceType = EnumHelper.ParseEnum&lt;ReferenceType&gt;(stream.FormData["ReferenceType"]);
             // -------------other code     
          }
          catch (Exception ex)
          {
              return FailureResponse(ex);
          }
  </code></pre>
  
  <p>I guess problem is that stream.FormData["ReferenceType"] is not set correctly from request.</p>
  
  <p>I don't want change the server code. because it working fine when you call from postman or browser.</p>
  
  <p>Can somebody pls help? Thanks</p>