C#檔案下載

iDotNetSpace發表於2010-05-31
string filepath = Server.MapPath("~/public/file.txt"); 
        FileInfo fi = new FileInfo(filepath);
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
        Response.AddHeader("Content-Length", fi.Length.ToString());
        Response.ContentType = "application/octet-stream";
        Response.Filter.Close();
        Response.WriteFile(fi.FullName);
        Response.End();

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-664086/,如需轉載,請註明出處,否則將追究法律責任。

相關文章