目的是根据已经登录的用户名创建一个与之同名的文件夹,再在文件夹下创建一个用户名.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:"); }
但是每次都会触发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:"); }
解决方案 »
- ASP.NET
- 如何写个页面允许用户访问并且可以编辑服务器上的那个excel文件
- 我为什么会得不到界面上的textbox呢?【F5在线中】
- 为什么我的正则表达式,在aspx.cs文件中使用时正常,当我将它放到.cs文件中作为静态函数时却没有结果
- 全国城市IP,经纬度的数据库
- 如何设置自定义的404错误!!,不要让我用程序写~~~~~!!!!!!!
- DataList 如何绑定 DataReader的数据?
- SpWeb1020是什么控件?高分求
- C#可不可以把关键字转换成非关键字?例如event?
- ASP程式报错,打开ADMIN后台管理的时候,进不去!为什么?
- 问题二--------sql中插入一条记录。然后马上就要取他的ID的方法是什么----问题二
- 交叉表的問題,
dt.Create() ;
试试
dt.Create() ;
File.Create(Server.MapPath(".") + "/" + Session["userName"] +"/"+Session["userName"] + ".htm");
这样因该可以创建你要的文件了
string sAbspath = Server.MapPath(".") + "/" + Session["userName"] +"/";
//如果路径不存在就试图创建根目录
if(!System.IO.Directory.Exists(sAbspath))
{
System.IO.Directory.CreateDirectory(sAbspath);
}