前台:
<asp:FileUpload ID="FileUpload1" runat="server" />
后台cs代码:
if (HttpContext.Current.Request.Files.Count > 0)
{HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
string savePath;
string dir = HttpContext.Current.Request.PhysicalApplicationPath;
savePath = dir + "Upload\\DocumentFiles\\";
savePath += Path.GetFileName(postedFile.FileName);
Session["savePath"] = savePath;
//FileName.Text = Path.GetFileName(postedFile.FileName);
//LG_BLL.VendorAttachment vendor = new LG_BLL.VendorAttachment();
vendor.InsertVendors(FileType.Text, FileName.Text, Vendortxt.Text);
if (File.Exists(savePath))
{
File.Delete(savePath);
}
postedFile.SaveAs(savePath);
}