title: .net Web Api 2 File Upload
body: <p>I trying to upload the file using web api and i follow the example in the site: </p>
  
  <p><a href="http://www.strathweb.com/2012/08/a-guide-to-asynchronous-file-uploads-in-asp-net-web-api-rtm/" rel="nofollow">http://www.strathweb.com/2012/08/a-guide-to-asynchronous-file-uploads-in-asp-net-web-api-rtm/</a></p>
  
  <p>It works great... but i don't want to override the file if file exists. Basically if the file already exists i want to save the file with a time stamp. </p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>
  
  <p>Minutes after I post the question I figure out. Here is the answer, is pretty simple... i just had a dumb moment. </p>
  
  <pre><code>  public class CustomMultipartFormDataStreamProvider : MultipartFormDataStreamProvider
  {
      private readonly string _rootDirectory = 'filesRoot';
      public CustomMultipartFormDataStreamProvider(string path) : base(path)
      {
      }
  
      public override string GetLocalFileName(HttpContentHeaders headers)
      {
          var filename = headers.ContentDisposition.FileName.Replace("\"", string.Empty);
          if (File.Exists(_rootDirectory + filename))
          {
              var fName = Path.GetFileNameWithoutExtension(_rootDirectory + filename);
              var extension = Path.GetExtension(_rootDirectory + filename); 
              return fName + '_' + DateTime.Now.Ticks + extension;
          }
          else
              return filename;
      }
  }
  </code></pre>