【发布时间】:2012-02-14 15:20:04
【问题描述】:
在这里,我从数据库中读取数据,循环遍历结果,并将包含 HTML 字符串行的列值传递给函数。此函数从 HTML 输入中提取<body> 标记和内容。
在调试中添加断点并逐步执行代码时,一切正常。删除断点后,只创建一个文件,但不抛出异常。代码:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
try
{
getBody(ds.Tables[0].Rows[i]["MailText"].ToString());
}
catch(Exception exp)
{
Response.Write(exp.ToString());
}
}
public void getBody(string html)
{
try
{
HtmlDocument HD = new HtmlDocument();
HD.LoadHtml(html);
string output = HD.DocumentNode.SelectSingleNode("//body") == null ? HD.DocumentNode.InnerHtml : HD.DocumentNode.SelectSingleNode("//body").InnerHtml;
using (StreamWriter sw = new StreamWriter(Server.MapPath("OnlyBody/") + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt"))
{
sw.Flush();
sw.Write(output);
if (sw != null)
{
sw.Close();
sw.Dispose();
}
}
}
catch (Exception exp)
{
throw exp;
}
finally
{
}
}
起初我以为问题出在文件流上,但即使在处理 StreamWriter 之后,错误仍然存在。
【问题讨论】:
标签: c# filestream streamreader