ASP.NETÏÂÔØÎļþ³öÏÖÌáʾ¿ò»òÕßÖ±½ÓÏÔʾÔÚä¯ÀÀÆ÷ÖÐ
ASP.NETÏÂÔØÎļþ³öÏÖÌáʾ¿ò»òÕßÖ±½ÓÏÔʾÔÚä¯ÀÀÆ÷ÖÐ
¼¼Êõ½»Á÷ 2008-06-20 11:44 ÔĶÁ42 ÆÀÂÛ0
×ֺţº ´ó´ó ÖÐÖРСС
1£º³öÏÖÎļþÏÂÔØÌáʾ¿ò
string strFile="F:\\a.doc";//·¾¶¸ù¾Ýʵ¼ÊÇé¿ö¶ø¶¨
if(!System.IO.File.Exists(strFile))
{
Response.Write("<script language='javascript'>alert('¶Ô²»Æð£¬Îļþ²»´æÔÚ£¡');</script>");
return;
}
Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312";
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream";
FileInfo fi=new FileInfo(strFile);
Response.AddHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode(fi.Name)) ;
Response.AddHeader("Content-Length",fi.Length.ToString());
byte[] tmpbyte=new byte[1024*8];
FileStream fs=fi.OpenRead();
int count;
while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)
{
Response.BinaryWrite(tmpbyte);
Response.Flush();
}
fs.Close();
Response.End();
2£ºÖ±½ÓÔÚä¯ÀÀÆ÷Öдò¿ª
string strFile="F:\\a.doc";//·¾¶¸ù¾Ýʵ¼ÊÇé¿ö¶ø¶¨
Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312";
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/msword";
Response.WriteFile(strFile);
3£º·â×°³ÉÀàµÄÎļþÏÂÔØ·½·¨µÄд·¨
///
/// ÔÚÒ³ÃæÖÐÏÔʾÏÂÔضԻ°¿ò²¢ÏÂÔØÖ¸¶¨µÄÎļþ£¬webPageΪҳÃæ¶ÔÏóÒýÓã¨Ò»°ã¸³ÖµPage)£¬filePathΪÏÂÔØÎļþÐéÄâ·¾¶£¬fileNameΪ¶Ô»°¿òÖÐÏÔʾµÄÎļþÃû
///
public static void DownloadFile(Page webPage, string filePath, string fileName)
{
HttpResponse Response = webPage.Response;
FileInfo aFile = new FileInfo(webPage.Server.MapPath(filePath));
Response.Clear();
Response.ClearHeaders();
Response.BufferOutp
Ïà¹ØÎĵµ£º
RowÄÚÕÒLabel¿Ø¼þ
//ÄÚ²¿¿Ø¼þʼþ
protected void LinkButton11_Click1(object sender, EventArgs e)
{
//ɾ³ý¶ÔÓ¦µÄÊÂÎñ
int ......
1. ´ò¿ªÐµĴ°¿Ú²¢´«ËͲÎÊý£º //´«ËͲÎÊý£º
response.write("£¼script£¾window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="++"’)£¼/script£¾")
¡¡¡¡//½ÓÊÕ²ÎÊý£º
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.Ϊ°´Å¥Ìí¼Ó¶Ô»°¿ò
Button1 ......
¼ÇÈ¡¼Ç¼¼¯
create procedure getArticle
as
select * from Article_Content
GO
asp.net µ÷Ó÷½·¨
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = Data.Connstr();
Conn.Open();
......
ASP.NETµÄ¹Ø¼üÄ¿±êÖ®Ò»ÊÇ´´½¨Ò»ÖÖÈÿª·¢ÈËÔ±Äܹ»ÏñWindowsÓ¦ÓóÌÐò¿ª·¢Õ߶¨ÖÆ×ÀÃæÓ¦ÓóÌÐòÄÇÑùµÄ¿ìËÙ¶¨ÖÆWeb FormsµÄģʽ¡£µ±È»WebÓ¦ÓóÌÐòÓ봫ͳ¸»¿Í»§¶ËÓ¦ÓóÌÐòÓкܴóµÄ²»Í¬£¬ÒªÊµÏÖÕâÖÖģʽÓÐÁ½¸ö¹Ø¼üµÄÕÏ°¡£
1.WebÓ¦ÓóÌÐòÊÇÔÚ·þÎñÆ÷¶ËÖ´ÐеģºÀýÈ磬¼ÙÉè´´½¨Ò»¸ ......
µÚÒ»²½£º´´½¨¶ÔÏó
µÚ¶þ²½£ºÉèÖÃÊôÐÔ
¢ÙpdsBooks.AllowPaging=true;
¢ÚpdsBooks.PageSize=5;
¢ÛpdsBooks.CurrentPageIndex=CurrentPage-1;
¢ÜpdsBooks.DataSource=BookManage.GetAllBooks();
µÚÈý²½£º°ó¶¨Êý¾ÝÔ´
DataList1.DataList=pdsBooks;
DataList1.DataBind(); ......