@创建txt 文本,并写人内容
public void LogWrite(string str)
{
//项目根目录
string path = Server.MapPath("~") + "error.txt";
if (!System.IO.File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(str);
sw.Flush();
sw.Close();
}
else
{
FileStream fs = new FileStream(path, FileMode.Append);
//文本写入
StreamWriter sw = new StreamWriter(fs);
sw.Write(str);
sw.Flush();
sw.Close();
}
}
/// <summary>
/// 客户端 Out Cpc 获取 PreLoadId
/// </summary>
public string GetOutCpcPreLoadId()
{
string fileContent = "";
string path = AppDomain.CurrentDomain.BaseDirectory + "cache_url\\PreLoad.bak";
if (System.IO.File.Exists(path))//判断是否有根目录
{
fileContent = System.IO.File.ReadAllText(path);
}
return fileContent;
}
/// <summary>
/// 客户端 Out Cpc 写入 PreLoadId
/// </summary>
public void SetOutCpcPreLoadId(string str)
{
//项目根目录
string path = AppDomain.CurrentDomain.BaseDirectory + "cache_url\\PreLoad.bak";
File.WriteAllText(path, str, Encoding.UTF8); //开始写入,但是之前有的会删掉
}