文件上传

  /// <summary>
  ///
  /// </summary>
  /// <returns></returns>
  public static string FileUp(System.Web.UI.HtmlControls.HtmlInputFile file)
  {
   if(file.Value != "")
   {
    int pos = file.Value.Trim().LastIndexOf("\\");
    string picName = file.Value.Trim().Substring(pos + 1);
    pos = picName.LastIndexOf(".");
    string excName = picName.Substring(pos);
    Guid gd = Guid.NewGuid();
    string newName = gd.ToString() + excName;
    //Save in server disk
    file.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("../../images/ProductPic/" + newName));

    return newName;
   }
   else
   {
    return "";
   }
  }

原文地址:https://www.cnblogs.com/King0502/p/2019371.html