这是我文件上传的代码事件: protected void btnUpLoad_Click(object sender, EventArgs e)
{ try
{ if (this.FuNodeRe.HasFile)
{ string path = Server.MapPath("~/UploadFiles/");
//重新命名上传文件
string fileName = System.DateTime.Now.ToString().Replace(" ", "").Replace("-", "").Replace(":", "");
string ext = System.IO.Path.GetExtension(FuNodeRe.FileName).ToLower();
string[] extention = new string[] { ".txt", ".rar", ".doc", ".pdf", ".pdg" };
bool j = false;
for (int i = 0; i < extention.Length; i++)
{
if (ext == extention[i])
{
j = true;
break;
}
}
if (j)
{
fileName += ext;
FuNodeRe.SaveAs(path + fileName);
FileName = path + fileName;
ViewState["FileName"] = fileName;
Response.Write("<script>alert('上传成功!');</script>");
}
else
{
Response.Write("<script>alert('文件格式不正确(.txt,.rar,.doc,.pdf,.pdg)!');</script>");
}
}
else
{
Response.Write("<script>alert('请先选择你要上传的文件!');</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('上传失败,请重新尝试!');</script>");
}
}当我选择 C:\Documents and Settings\Administrator\桌面\入党积极分子党训班安排表(第一期).doc 这个路径上传时,可以上传该.doc文件。
但当我选择 C:\Documents and Settings\Administrator\桌面\党课材料.rar 这个路径时却不能上传.rar文件。
到底是怎么一回事呢?大家帮帮忙,谢谢了...
{ try
{ if (this.FuNodeRe.HasFile)
{ string path = Server.MapPath("~/UploadFiles/");
//重新命名上传文件
string fileName = System.DateTime.Now.ToString().Replace(" ", "").Replace("-", "").Replace(":", "");
string ext = System.IO.Path.GetExtension(FuNodeRe.FileName).ToLower();
string[] extention = new string[] { ".txt", ".rar", ".doc", ".pdf", ".pdg" };
bool j = false;
for (int i = 0; i < extention.Length; i++)
{
if (ext == extention[i])
{
j = true;
break;
}
}
if (j)
{
fileName += ext;
FuNodeRe.SaveAs(path + fileName);
FileName = path + fileName;
ViewState["FileName"] = fileName;
Response.Write("<script>alert('上传成功!');</script>");
}
else
{
Response.Write("<script>alert('文件格式不正确(.txt,.rar,.doc,.pdf,.pdg)!');</script>");
}
}
else
{
Response.Write("<script>alert('请先选择你要上传的文件!');</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('上传失败,请重新尝试!');</script>");
}
}当我选择 C:\Documents and Settings\Administrator\桌面\入党积极分子党训班安排表(第一期).doc 这个路径上传时,可以上传该.doc文件。
但当我选择 C:\Documents and Settings\Administrator\桌面\党课材料.rar 这个路径时却不能上传.rar文件。
到底是怎么一回事呢?大家帮帮忙,谢谢了...
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货