很简单的一段后台生成文件的代码
public partial class TestGenerate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
makeHtml("download/dd.txt", "woshiz-asd");
} public void makeHtml(string fname, string ftext)
{
string _FileDir = HttpContext.Current.Server.MapPath(Path.GetDirectoryName(fname));
if (!Directory.Exists(_FileDir))
Directory.CreateDirectory(_FileDir);
System.IO.StreamWriter sw = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath(fname));
sw.Write(ftext);
sw.Flush();
sw.Close();
sw.Dispose();
HttpContext.Current.Response.Write("成功生成:" + fname);
}
}在调试运行和运行的时候都很正常,但在发布后,IIS7.0 ,通过浏览器访问就无法生成文件。
而且也不报错,并且在页面上也 出现了 "成功生成:download/dd.txt"的字
也就是说 makeHtml这个文件确实是执行了,但为什么没有文件生成呢?谢谢
public partial class TestGenerate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
makeHtml("download/dd.txt", "woshiz-asd");
} public void makeHtml(string fname, string ftext)
{
string _FileDir = HttpContext.Current.Server.MapPath(Path.GetDirectoryName(fname));
if (!Directory.Exists(_FileDir))
Directory.CreateDirectory(_FileDir);
System.IO.StreamWriter sw = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath(fname));
sw.Write(ftext);
sw.Flush();
sw.Close();
sw.Dispose();
HttpContext.Current.Response.Write("成功生成:" + fname);
}
}在调试运行和运行的时候都很正常,但在发布后,IIS7.0 ,通过浏览器访问就无法生成文件。
而且也不报错,并且在页面上也 出现了 "成功生成:download/dd.txt"的字
也就是说 makeHtml这个文件确实是执行了,但为什么没有文件生成呢?谢谢
sw.Write(ftext);
sw.Flush();
这些语句有没有执行。你都没有判断是否执行成功就HttpContext.Current.Response.Write("成功生成:" + fname);当然不管你有没有运行成功就都显示“成功生成”了。并且在页面上也 出现了 "成功生成:download/dd.txt"的字
也就是说 makeHtml这个文件确实是执行了, 这句话如果分成两段,那么上面一段推段出下面一段没错,但是makeHtml执行了就能说名生成文件执行了吗?用try catch 看看