ASP.NET实现从服务器下载文件(记录)
假设在服务器的根目录下有个名为Download的文件夹,这个文件夹存放一些提供给引用程序下载的文件..
public void DownloadFile(string path, string name)
{
try
{
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
相关文档:
(1)了解到namespace的3中引用方法
(2)了解了assembly:类似于动态链接库.dll的东西。分为公共和私有的assembly。前者存放在GAC中。
如果你的程序要使用某一类库,有两步要做:1,把application链接到assembly;2,引入namespace。
(3) ......
asp.net中的html控件runat=server时的映射 1、标准xhtml标签:http://blog.csdn.net/TangZhongxin/archive/2009/07/31/4398487.aspx 2、绝大多数标签都映射到“System.Web.UI.HtmlControls.HtmlGenericControl”,它们的共同特性是“信息只读,仅供显示的标记”:
div,span,p,h1,h2,h3,h4,h5,h6,ul,li,dl,dt,dd, ......
Process p = new Process();
p.StartInfo.FileName = "cmd.exe"; //設定程序名
p.StartInfo.Arguments = "/c " command; //設定程式執行參數
p.StartInfo.UseShellExecute = false; //關閉Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向標準 ......