马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C#每天定时生成文本文件(.csv)

[复制链接]
查看4827 | 回复3 | 2015-2-6 13:26:19 | 显示全部楼层 |阅读模式
C#每天定时生成文本文件(每小时往文件中写内容),文件中的内容有两列,一列(date)是取生成文件时间,另一列(snow)是随机数,每一天的文件都是不同的(根据日期)
ibcadmin | 2015-2-9 09:54:17 | 显示全部楼层
[C#] 纯文本查看 复制代码
/// <summary>
      /// 写日志
      /// </summary>
      /// <param name="strMsg"></param>
      /// <param name="strFileName"></param>
      public static void WriteLogContent(string strFileName,string strMsg)
      {
          try
          {
              strMsg += "        " + System.DateTime.Now + "\r\n";
              string strPath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + strFileName;
              if (!File.Exists(strPath))
              {
                  Directory.CreateDirectory(strPath);
              }
              string sname = System.DateTime.Now.ToString("yyyy-MM-dd");
              FileStream fs = new FileStream(strPath + "/" + sname + ".csv", FileMode.OpenOrCreate, FileAccess.Write);
              StreamWriter sw = new StreamWriter(fs);
              sw.BaseStream.Seek(0, SeekOrigin.End);
              sw.Write(strMsg);
              sw.Flush();
              sw.Close();
          }
          catch
          { }
      }


第一个参数是你的路径 第二个是内容

内容就是你的随机数

然后做个计时器 每天执行这个方法就行了
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
test123 | 2015-2-15 17:45:31 | 显示全部楼层
非常好的资料。
呵呵 | 2015-3-6 17:27:14 | 显示全部楼层
卡NK你
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则