写文件

//要先引用输入输出包
using System.IO;
 //获取webservice所在的路径;
 string path = Server.MapPath("WSLicence.asmx");      
 //截取文件夹路径
 string folderPath = path.Substring(0, path.LastIndexOf('\\'));
 string fileName = folderPath + "register.dat";
 //如果文件夹不存在,创建文件
 if (!File.Exists(fileName))
 {
      FileStream fs = new FileStream(folderPath + "register.dat", FileMode.CreateNew);
      string content = serial + code + key;
      MD5 md5 = new MD5CryptoServiceProvider();
      byte[] result = System.Text.Encoding.UTF8.GetBytes(content);
      byte[] crypoResult = md5.ComputeHash(result);

      fs.Write(crypoResult, 0, crypoResult.Length);
      //清空缓存
      fs.Flush();
      fs.Close();
}

posted @ 2009-09-02 14:31  蒋凯  阅读(169)  评论(0编辑  收藏  举报