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
请教是怎么回事。在线等,急!
#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
请教是怎么回事。在线等,急!
...全文
相关推荐
commons-fileupload组件上传问题
整个代码 博文链接:https://canofy.iteye.com/blog/143075
关于ASP.NET2.0 FILEUPLOAD上传文件大小设置问题
关于ASP.NET2.0 FILEUPLOAD上传文件大小设置问题解决方案!
updatepanel中不能使用fileupload的弥补方法[IFrame方式]
直接使用FileUpload,服务端是无法找到上传文件的。updatepanel中不能使用fileupload的弥补方法[IFrame方式]
FileUpload实例
apache的产品,jsp上传组件FileUpload实例,将浏览文件上传至工程根目录saveRoot文件夹。请放心下载
ASP.NET.FileUpload控件
FileUpload控件的基本用法 .



