目的是根据已经登录的用户名创建一个与之同名的文件夹,再在文件夹下创建一个用户名.htm文件
但是每次都会触发catch,为什么?
另外:如果不创建文件夹,就在与该页面平行的路径下创建用户名.htm是可以成功的
请帮忙解决,谢谢
 try
        {
            using (StreamWriter sw = new StreamWriter(Server.MapPath(".") + "/" + Session["userName"] +"/"+ Session["userName"] + ".htm", false, System.Text.Encoding.GetEncoding("GB2312")))
            { sw.WriteLine(htmltext);
              sw.Flush();                sw.Close();
                Response.Redirect("~/" + Session["userName"] +"/"+ Session["userName"] + ".htm");            }        }        catch
        {            Response.Write("The file could not be wirte:");        } 

解决方案 »

  1.   

    文件夹不是这样想建就建立的,要用到IO中的Dictionary类建个文件夹.
      

  2.   

    thaks,给一点代码提示?谢谢啊
      

  3.   

       DirectoryInfo  dt = new DirectoryInfo(Server.MapPath(".") + "/" + Session["userName"] +"/");
            dt.Create() ;
    试试
      

  4.   

    DirectoryInfo  dt = new DirectoryInfo(Server.MapPath(".") + "/" + Session["userName"] +"/"); 
            dt.Create() ;
    File.Create(Server.MapPath(".") + "/" + Session["userName"] +"/"+Session["userName"] + ".htm");
    这样因该可以创建你要的文件了
      

  5.   

    network service用户需要你的应用程序目录的写入权限。
      

  6.   

           
           string sAbspath = Server.MapPath(".") + "/" + Session["userName"] +"/";  
           //如果路径不存在就试图创建根目录
            if(!System.IO.Directory.Exists(sAbspath))
            {
                System.IO.Directory.CreateDirectory(sAbspath);            
            }