public static void ExportResultLog(System.Data.DataTable dt, string fileName, string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
} string strPath = path + fileName; StringBuilder strColu = new StringBuilder();
StringBuilder strLineValue = new StringBuilder();
try
{
if (System.IO.File.Exists(strPath))
{
string[] stringlines = System.IO.File.ReadAllLines(strPath, Encoding.Default);
string line = string.Empty;
foreach (string readLine in stringlines)
{
line += readLine + "\r\n";
}
line = line.Remove(line.Length - 2, 2); System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath, false, Encoding.GetEncoding("UTF-8")); sw.WriteLine(line); foreach (DataRow dr in dt.Rows)
{
strLineValue.Remove(0, strLineValue.Length);
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
strLineValue.Append(ReplaceChar(dr[i] == DBNull.Value ? "" : dr[i].ToString()));
strLineValue.Append(",");
}
strLineValue.Remove(strLineValue.Length - 1, 1);
sw.WriteLine(strLineValue.ToString());
}
sw.Close();
}
else
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath, false, Encoding.GetEncoding("UTF-8")); for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
strColu.Append(dt.Columns[i].ColumnName);
strColu.Append(",");
}
strColu.Remove(strColu.Length - 1, 1);
sw.WriteLine(strColu); foreach (DataRow dr in dt.Rows)
{
strLineValue.Remove(0, strLineValue.Length);
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
strLineValue.Append(ReplaceChar(dr[i] == DBNull.Value ? "" : dr[i].ToString()));
strLineValue.Append(",");
}
strLineValue.Remove(strLineValue.Length - 1, 1);
sw.WriteLine(strLineValue.ToString());
}
sw.Close();
}
}
catch (Exception ex)
{
throw ex;
} } public static void ExportLog(System.Data.DataTable dtLogInfo, string fileName, string path)
{
string strPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path); if (!System.IO.Directory.Exists(strPath))
{
System.IO.Directory.CreateDirectory(strPath);
} strPath = path + fileName; StringBuilder strColu = new StringBuilder();
StringBuilder strValue = new StringBuilder();
try
{
if (System.IO.File.Exists(strPath))
{
string[] stringlines = System.IO.File.ReadAllLines(strPath, Encoding.Default);
string line = string.Empty;
foreach (string readLine in stringlines)
{
line += readLine + "\r\n";
} System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath, false, Encoding.GetEncoding("UTF-8"));
strValue.Remove(0, strValue.Length);
for (int i = 0; i <= dtLogInfo.Columns.Count - 1; i++)
{
strValue.Append(ReplaceChar(dtLogInfo.Rows[0][i] == DBNull.Value ? "" : dtLogInfo.Rows[0][i].ToString()));
strValue.Append(",");
}
strValue.Remove(strValue.Length - 1, 1);
string value = line + strValue.ToString();
sw.WriteLine(value);
sw.Close();
}
else
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(strPath, false, Encoding.GetEncoding("UTF-8")); for (int i = 0; i <= dtLogInfo.Columns.Count - 1; i++)
{
strColu.Append(dtLogInfo.Columns[i].ColumnName);
strColu.Append(",");
}
strColu.Remove(strColu.Length - 1, 1);
sw.WriteLine(strColu); strValue.Remove(0, strValue.Length);
for (int i = 0; i <= dtLogInfo.Columns.Count - 1; i++)
{
strValue.Append(ReplaceChar(dtLogInfo.Rows[0][i] == DBNull.Value ? "" : dtLogInfo.Rows[0][i].ToString()));
strValue.Append(",");
}
strValue.Remove(strValue.Length - 1, 1);
sw.WriteLine(strValue.ToString()); sw.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}

  

最新文章

  1. shift
  2. 用Google Analytics跟踪JavaScript Errors (译)
  3. IE中Ajax数据缓存的问题
  4. ASP无惧上传类不能上传中文双引号文件及ASP函数InStr存在bug
  5. 表达式语言--在MVC中应用表达式语言
  6. SuperSocket入门(三)-Telnet多服务实例和服务实例交互配置详解
  7. 【转载 | 笔记】IIS无法删除应该程序池 因为它包含X个应用程序
  8. web的分页方法
  9. axis2与cxf区别
  10. Apache与Nginx
  11. Python学习笔记9-多线程和多进程
  12. redis-master/slave模式
  13. java.lang.ClassCastException: java.lang.Short cannot be cast to java.lang.String(Short类型无法强转成String类型)
  14. WEB中会话跟踪[转]
  15. 在 CSS 中,width 和 height 指的是内容区域的宽度和高度
  16. DevExpress v17.2新版亮点—DevExtreme篇(一)
  17. 互评Beta版本——二次元梦之队——“I Do”
  18. week 4 Vocabulary in paper
  19. Problem G: 切煎饼
  20. GB2312简体中文编码表

热门文章

  1. 重启PHP命令
  2. BZOJ 1151 傲娇的人 排序
  3. 设计模式 - 策略模式(Strategy Pattern) 具体解释
  4. android121 zhihuibeijing SlidingMenu(侧边栏效果,使用开源库)
  5. 双tomcat的部署
  6. Git链接到自己的Github(1)简单的开始
  7. 在饼图上显示百分比值(报表生成器和 SSRS)
  8. ClientKey实现登录QQ空间,并设置背景音乐
  9. Hibernate学习笔记--------2.一多|多多的CRUD
  10. VFS对象总结