title: Change filename on file upload in .net (asp)
body: <p>How to change file name on upload ?</p>
  
  <p>I have such code :</p>
  
  <pre><code>&lt;%@ WebHandler Language="C#" Class="Upload" %&gt;
  
  using System;
  using System.Web;
  using System.IO;
  
  public class Upload : IHttpHandler {
     public void ProcessRequest(HttpContext context) {
         HttpPostedFile oFile = context.Request.Files["Filedata"];
       string newFileName1 = HttpContext.Current.Server.MapPath(@context.Request["orderID"]);
       string newFileName2 = HttpContext.Current.Server.MapPath(@context.Request["productCombinationString"]);
       string newName;
         if(newFileName2 != "" &amp;&amp; newFileName2 != null &amp;&amp; newFileName2 != "&lt;!--@Ecom:productCombinationString--&gt;") {
             newName = newFileName1 + newFileName2 + oFile.ContentType;
         } else {
             newName = newFileName1 + oFile.ContentType; 
         }
  
       string sDirectory = HttpContext.Current.Server.MapPath(@context.Request["folder"]);
       oFile.SaveAs(sDirectory + "/" + oFile.FileName);
       if (!Directory.Exists(sDirectory)) Directory.CreateDirectory(sDirectory);
       context.Response.Write("1");
     }
     public bool IsReusable {
        get { return false; }
     }
  }
  </code></pre>
  
  <p>And if i change oFile.Filename to newName it does not work ... what is the problem ? :)
  Thank you</p>