📄 printfile.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
public class PrintFile
{
/// <summary>
/// 运行日志
/// </summary>
/// <param name="path">根目录</param>
/// <param name="log">日志内容</param>
public static void PrintRunLog(string path, string log)
{
path += "systemlog/run.log";
if (!File.Exists(path))
{
StreamWriter Create = new StreamWriter(path, true, System.Text.Encoding.Default);
Create.Close();
}
StreamWriter writelog = new StreamWriter(path, true, System.Text.Encoding.Default);
writelog.WriteLine(DateTime.Now.ToString() + ":" + log);
writelog.Close();
}
/// <summary>
/// 异常日志
/// </summary>
/// <param name="path">根目录</param>
/// <param name="log">异常内容</param>
public static void PrintError(string path, string log)
{
path += "systemlog/" + DateTime.Now.ToString("yyyyMMdd") + ".log";
if (!File.Exists(path))
{
StreamWriter Create = new StreamWriter(path, true, System.Text.Encoding.Default);
Create.Close();
}
StreamWriter writelog = new StreamWriter(path, true, System.Text.Encoding.Default);
writelog.WriteLine(DateTime.Now.ToString("HH:mm:ss") + ":" + log);
writelog.Close();
}
/// <summary>
/// 生成静态页面
/// </summary>
/// <param name="url">页面</param>
/// <param name="path">路径</param>
/// <returns></returns>
public static bool PrintHtml(string url, string path)
{
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 20000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
string htmlcode = reader.ReadToEnd().Replace("\n", "").Replace("style=\"display:inline-block;\"", "class=\"static\"").Replace("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">", "");
htmlcode = Regex.Replace(htmlcode, "<div class\\=\"pagetop_2\">(.|\n)+?</script>", "<iframe id=\"iframe_\" src=\"pagetop.aspx\" width=\"980\" height=\"0\" frameborder=\"0\" scrolling=\"no\"></iframe>");
htmlcode = htmlcode.Replace("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />", "");
htmlcode = htmlcode.Replace("<div class=\"div_body_\">", "<div class=\"div_body_\" style=\"margin-left:10px;\">");
htmlcode = htmlcode.Replace("<input name=\"Text_CurrentPage\" type=\"text", "<input name=\"Text_CurrentPage\" type=\"hidden");
htmlcode = htmlcode.Replace("<input name=\"Text_PageCount\" type=\"text", "<input name=\"Text_PageCount\" type=\"hidden");
htmlcode = htmlcode.Replace("__doPostBack('LinkButton_Next','')", "static_next();form_page.submit();");
htmlcode = htmlcode.Replace("__doPostBack('LinkButton_Last','')", "static_last();form_page.submit();");
reader.Close();
response.Close();
StreamWriter write = new StreamWriter(path, false, System.Text.Encoding.UTF8);
write.Write(htmlcode);
write.Close();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 生成js文件
/// </summary>
/// <param name="content">内容</param>
/// <param name="path">路径</param>
/// <returns></returns>
public static bool PrintJs(string content, string path)
{
try
{
StreamWriter write = new StreamWriter(path, false, System.Text.Encoding.UTF8);
write.Write(content);
write.Close();
return true;
}
catch
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -