c# 属于自己封装的类库(静态页面生成三种方式、导出文件类)
源代码完全公开,欢迎大家灌水!部分代码如下
1.
//Response.ContentType是输出流的 HTTP MIME 类型
//Response.ContentType --- word文件
//application/vnd.ms-excel --- excel文件
//更多格式请参考http://walleyekneel.iteye.com/blog/979524
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//attachment --- 作为附件下载
//inline --- 在线打开
//filename如过是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)
//进行进行编码,以解决文件名乱码的问题
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
2.
/// <summary>
/// 根据远程地址生成静态网页
/// </summary>
/// <param name="path">远程地址路径如http://localhost:9953/WebSite1/Default3.aspx</param>
/// <param name="templatename">生成静态文件的路径如a/1.html</param>
public static void GetHtml(string remotepath, string templatepath)
{
WebRequest wr = WebRequest.Create(remotepath);
WebResponse wrp = wr.GetResponse();
StreamReader sr = new StreamReader(wrp.GetResponseStream(), Encoding.GetEncoding("gb2312"));
string str = sr.ReadToEnd();
sr.Close();
StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(templatepath), false, Encoding.GetEncoding("gb2312"));
sw.Write(str);
sw.Flush();
sw.Close();
}
迟点补充:分页、通过ID带出表中其他值、数据库备份、还原
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架