File Download Tips for asp.net
use http header
protected void Page_Load(object sender, EventArgs e)
{
string format = Convert.ToString(ViewData["format"]);
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("·ÑÓñ¨Ïú±í", Encoding.UTF8) + string.Format(".{0}",format));
//²âÊÔÖз¢ÏÖ£ºÈç¹ûÒªÏëÔÚIEÖÐÖ±½Ó´ò¿ªPDF£¬ÉÏÐдúÂ룬²»ÄÜÓУ¡£¡·ñÔò¼´Ê¹¿Í»§¶ËÓÐÉèÖã¬Ò²»áʹÓà Adobe Reader/Acrobat ´ò¿ª
Response.ContentType = string.Format("application/{0}",format);
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(ViewData.Model);
Response.Flush();
//prevent render html to client(critical)
Response.End();
request to doc directly
Response.Redirect(“http://localhost:2222/Docs/abc.doc”, true);
Tips:
ÖÁÓÚ¿Í»§¶ËʹÓÃä¯ÀÀÆ÷´ò¿ª(µ±È»±ØÐëÒªÏàÓ¦µÄä¯ÀÀÆ÷²å¼þÖ§³Ö)£¬»¹ÊÇÏàÓ¦µÄapplication (MS-Word,Adobe Reader),´ò¿ªÇ°ÊÇ·ñÌáʾÏÂÔØ£¬Server¶ËÊÇÎÞ·¨¿ØÖƵģ¬Õâ¸öºÍÓû§ÉèÖÃÓйØÏµ¡£¼ûͼ
Ïà¹ØÎĵµ£º
Iframe±ê¼Ç£¬Óֽи¡¶¯Ö¡±ê¼Ç£¬Äã¿ÉÒÔÓÃËü½«Ò»¸öHTMLÎĵµÇ¶ÈëÔÚÒ»¸öHTMLÖÐÏÔʾ¡£Ëü²»Í¬ÓÚFrame±ê¼Ç×î´óµÄÌØÕ÷¼´Õâ¸ö±ê¼ÇËùÒýÓõÄHTMLÎļþ²»ÊÇÓëÁíÍâµÄHTMLÎļþÏ໥¶ÀÁ¢ÏÔʾ£¬¶øÊÇ¿ÉÒÔÖ±½ÓǶÈëÔÚÒ»¸öHTMLÎļþÖУ¬ÓëÕâ¸öHTMLÎļþÄÚÈÝÏ໥Èںϣ¬³ÉΪһ¸öÕûÌ壬ÁíÍ⣬»¹¿ÉÒÔ¶à´ÎÔÚÒ»¸öÒ³ÃæÄÚÏÔʾͬһÄÚÈÝ£¬¶ø²»±ØÖظ´Ð´ÄÚÈ ......
using System;
using System.Collections.Generic;
using System.Text;
namespace PublicClass
{
public static class Log
{
public static void WriteLine(string line)
{
......
HyperLink Web ·þÎñÆ÷¿Ø¼þ¿ÉÔÚÍøÒ³ÉÏ´´½¨Á´½Ó£¬Ê¹Óû§¿ÉÒÔÔÚÓ¦ÓóÌÐòÖеÄÒ³¼äÒÆ¶¯¡£
Ò»¡¢±³¾°
ʹÓà HyperLink ¿Ø¼þµÄÖ÷ÒªÓŵãÊÇ¿ÉÒÔÔÚ·þÎñÆ÷´úÂëÖÐÉèÖÃÁ´½ÓÊôÐÔ¡£ÀýÈ磬Äú¿ÉÒÔ¸ù¾ÝÒ³ÃæÖеÄÌõ¼þ¶¯Ì¬¸ü¸ÄÁ´½ÓÎı¾»òÄ¿±êÒ³¡£
°²È«ËµÃ÷£º Ó볬Á´½ÓÏà¹ØÁªµÄ URL ¿ÉÄܻᱻÓû§¶ñÒâ´Û¸ ......
1. ´ò¿ªÐµĴ°¿Ú²¢´«ËͲÎÊý£º
´«ËͲÎÊý£º
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
½ÓÊÕ²ÎÊý£º
string a = Request.QueryString("id");
string b = Request.QueryStrin ......