执行以下部分代码后,文件未保存在内容文件夹中。在按钮上单击我将excel文件保存到根目录的内容文件夹中。
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".xls", ".xlsx", ".xlsm" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Content/") + FileUpload1.FileName);
break;
}
}
}
else
{
Response.Write("");
}
}