双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

FileUpload问题

friend43 friend43 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题描述:使用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
请教是怎么回事。在线等,急!
...全文
评论 11
收藏 已收藏
分享
返回顶部
friend43
.NET社区 62,274 成员 668,968 内容