title: How to upload image with custom name with it's original extension?
body: <p>I'm trying to upload images in a form which I basically have done already, but I want the image to be named specifically for each user who registers.</p>
  
  <p>For example, each email will be unique, if there is another email already in the database then the form will return false (it will not let him/her register).</p>
  
  <p>So what I did was change the file name to the email he/she typed in the form.</p>
  
  <p>But now the file will not have it's original extension (.jpg .png etc).</p>
  
  <p>Is there a way I could pull the file original extension?</p>
  
  <p>Here's what I have in my controller:</p>
  
  <pre><code>[HttpPost]
  public AcitonResult Register(Registration signingUp, HttpPostedFileBase avatar)
  {
      var db = new AvatarDBEntities();
      if (ModelState.IsValid)
      {
          var FindEmail = db.tblProfiles.FirstOrDefault(e =&gt; e.PROF_Email == signingUp.Email);
  
          if (FindEmail == null)
          {
              var Data = db.tblProfiles.Create();
              Data.PROF_Email = signingUp.Email;
  
              if (avatar != null)
              {
                  string profpic = System.IO.Path.GetFileName(avatar.FileName);
                  string profpic_name = signingUp.Email + ".jpg"; //this is what I'm trying to change
                  string path = System.IO.Path.Combine(Server.MapPath("~/assets/images/user_images/avatars"), profpic_name);
  
                  avatar.SaveAs(path);
              }
  
              db.tblProfiles.Add(Data);
              db.SaveChanges();
          }
          else
          {
              ModelState.AddModelError("Email", "That Email already exist.");
              return View();
          }
      }
      return View();
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@using (Html.BeginForm("Register", "Main", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
      @Html.TextBoxFor(r =&gt; r.Email, new { @class = "custom-input Email" })&lt;br/&gt;
      @Html.ValidationMessageFor(a =&gt; a.Email)&lt;br/&gt;
      &lt;label for="avatar"&gt;Profile picture:&lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;br /&gt;
      &lt;input type="file" name="avatar" id="avatar" /&gt;&lt;br/&gt;
      &lt;input type="submit" /&gt;
  }
  </code></pre>
  
  <p>The image is in the folder with the name as their email and the extension of <code>.jpg</code>.</p>
  
  <p>I just want to pull the extension of the original file and add it after it pulls the email value.</p>
  
  <p>Thanks.</p>