title: Uploading a file to Sitecore keeping the extension in the DisplayName
body: <p>As the title says, I'm trying to upload a file to somewhere in my Sitecore tree from the web and I want to keep the file's extension in the DisplayName of the item.</p>
  
  <p>I tried using MediaCreator, but it requires a specific filepath which I do not know when I let people select a file using asp:FileUpload. So that's no good.</p>
  
  <p>I'm now using the asp:FileUpload in combination with a pipeline. When I use Sitecore.Pipelines.Upload.Save from Sitecore.Kernel it works except it removes the extension of the file from the DisplayName. So I created a custom pipeline method that looks like this:</p>
  
  <pre><code>using System;
  using System.IO;
  using Sitecore.Diagnostics;
  using Sitecore.IO;
  
  namespace Sitecore.Pipelines.Upload
  {
      public class CustomSave
      {
          public void Process(UploadArgs args)
          {
              foreach (string key in args.Files)
              {
                  var file = args.Files[key];
  
                  if (file != null &amp;&amp; file.FileName.Length &gt; 0 &amp;&amp; file.ContentLength &gt; 0)
                  {
                      var filename = FileUtil.MakePath(args.Folder, Path.GetFileName(file.FileName), '/');
                      try
                      {
                          if (!args.Overwrite)
                          {
                              filename = FileUtil.GetUniqueFilename(filename);
                          }
                          file.SaveAs(filename);
  
                          EventDispatcher.DispatchTrace("File has been uploaded: " + filename);
                      }
                      catch (Exception ex)
                      {
                          Log.Error("Could not save posted file: " + filename, ex, this);
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>The problem I now face is that it's trying to save to my C:\ disk instead of the Sitecore database.</p>
  
  <p>Any suggestions on how to write to the correct destination?</p>
  
  <p>The end goal, as explained, is to use the client friendly asp:FileUpload to select a file and upload it to a specific path in Sitecore retaining the file's extension in its DisplayName. If you have another way to do that I'd like to hear about it too.</p>