我在我的电脑上写的程序拷贝到同事的电脑上重新编译后运行,就出了问题:在我的电脑(XP系统),运行没有任何问题,但是将原代码拷贝到同事的电脑(2000系统)上编译后,就不能删除以汉字命名的文件,请问高手,向这个问题怎么解决,
下面是代码:
string MID = HttpUtility.UrlDecode(Request.QueryString["MID"].ToString().Trim()); ///// 文件所在的文件加的名称  xxx
string FileName = HttpUtility.UrlDecode(Request.QueryString["FileName"].ToString().Trim());  ///// 文件的部分路径和文件名称 :xxx/中国.txt string FilePath = "../../FileMateriel/"+ FileName;  /// 完整的相对路径 try
{
FilePath = System.Web.HttpContext.Current.Server.MapPath(FilePath).ToString();
File.Delete(FilePath);
Response.Write("<script language=javascript>window.alert('指定附件删除操作成功!');window.location.href='Amend.aspx?MID="+MID.ToString()+"';</script>");
//Response.End();
}
catch (System.Exception ex)
{
Response.Write("<script language=javascript>window.alert('指定附件删除操作失 "+ ex.Message +" 败,请重新操作!');window.location.href='Amend.aspx?MID="+MID.ToString()+"';</script>");
//Response.End();
}现在的提示的错误有两种:一是,显示删除成功,但是实际上并不成功,二是:提示文件路径中含有非法字符,
高手们,这个问题怎么解决,??我都快被逼疯了 !!!
谢谢大家了 !!!!

解决方案 »

  1.   

    先判断下文件的路径filepath是否正确
    FilePath = System.Web.HttpContext.Current.Server.MapPath(FilePath).ToString(); 
    执行完之后FilePath值是什么?
    另外目录是否有操作权限
      

  2.   

    简单..把那个.Response.Write(" <script language=javascript>window.alert('指定附件删除操作成功!');window.location.href='Amend.aspx?MID="+MID.ToString()+"'; </script>"); 改成
    Response.Write(" <script language=javascript>window.alert('指定附件删除操作成功!');window.location.href='Amend.aspx?MID=escape('"+MID.ToString()+"')'; </script>"); 
    把参数用escape转换一下..这样就不会乱码了..