asp.net页面功能之【设为桌面图标】
第一步:创建一个空页面,如: SetDesktop.aspx【名字随便叫,不限定】
第二步:后台代码
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 Response.Clear();
4 Response.ContentType = "APPLICATION/OCTET-STREAM";
5
6 //解决中文乱码
7 Response.Buffer = true;
8 Response.Charset = "gb2312";
9 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
10 Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode("百度", System.Text.Encoding.UTF8) + ".url\"");
11
12 Response.Write("[InternetShortcut] \r\n");
13 Response.Write("URL=http://www.baidu.com/ \r\n"); //链接
14 Response.Write("IDList= \r\n");
15 Response.Write("IconFile= \r\n"); //图标文件
16 Response.Write("IconIndex=1 \r\n");
17 Response.Write("[{000214A0-0000-0000-C000-000000000046}] \r\n");
18 Response.Write("Prop3=19,2 \r\n");
19 Response.End();
20 }
或:
1 protected void SetShortCut()
2 {
3 Response.ClearContent();
4
5 if (HttpContext.Current.Request.Browser.Browser != "IE")
6 {
7 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"谷歌.url\"");
8 }
9 else
10 {
11 string sitename = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("谷歌.url"));
12 Response.AddHeader("content-disposition", "attachment; filename=" + sitename);
13 }
14 Response.ContentType = "APPLICATION/OCTET-STREAM";
15
16 Response.Write("[InternetShortcut]\r\n");
17 Response.Write("URL=http://www.google.com\r\n");
18 Response.Write("IDList=\r\n");
19 Response.Write("[{000214A0-0000-0000-C000-000000000046}]\r\n");
20 Response.Write(" Prop3=19,2\r\n");
21 Response.End();
22
23 }
第三步:调用<a href="SetDesktop.aspx">设为桌面图标</a>
posted on 2012-03-27 18:39 zhangtao1212 阅读(381) 评论(0) 编辑 收藏 举报