string ext = ".jpg"; if (System.IO.Path.GetExtension(Request.Files[file].FileName).Length == 4 || System.IO.Path.GetExtension(Request.Files[file].FileName).Length == 5) ext = System.IO.Path.GetExtension(Request.Files[file].FileName); string name = Request.Files[file].FileName + ext; string path = System.IO.Path.Combine(Server.MapPath("~/uploads"), name); if (System.IO.File.Exists(path)) System.IO.File.Delete(path); Request.Files[file].SaveAs(path); ViewBag.FileName = name;