FileUpload问题
问题描述:使用FileUpload控件,运行发布后的网站进行文件上传,但无法上传上去。如果用F5调试运行程序,则能上传成功。代码如下:
#region 上传文件到指定目录
if (fuExcel.HasFile)
{
string fileExtension = Path.GetExtension( fuExcel.FileName ).ToLower(); //获取上传文件扩展名
string[] alloweExtensions ={ ".xls" }; //定义充许上传得扩展名
//判断上传的文件扩展名是否有效
for (int i = 0; i < alloweExtensions.Length; i++)
{
if (fileExtension == alloweExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
string serverPath = Server.MapPath( Request.ApplicationPath );
fuExcel.PostedFile.SaveAs( serverPath + "\\UploadFile\\" + fuExcel.FileName );
//fuExcel.PostedFile.SaveAs( path + "\\" + fuExcel.FileName ); //把文件上传到指定的目录里
upPath = serverPath + "UploadFile\\" + fuExcel.FileName;
}
catch (Exception ee)
{
//Response.Write( "<script language='javascript'>alert('文件上传失败!');window.location.href='DataIn.aspx';</script>" );
ScriptManager.RegisterClientScriptBlock( this.Page, this.GetType(), "Error", "alert('文件上传失败!');", true );
return;
}
}
else
{
//Response.Write( "<script language='javascript'>alert('上传文件类型不正确!');window.location.href='DataIn.aspx';</script>" );
ScriptManager.RegisterClientScriptBlock( this.Page, this.GetType(), "Error", "alert('上传文件类型不正确!');", true );
return;
}
#endregion
请教是怎么回事。在线等,急!