ASP.NET将网页设为桌面图标实现

创建SetDesktop.aspx页面

然后添加如下代码: 

protected void Page_Load(object sender, EventArgs e)
        {
            string Url = Request.QueryString["url"];
            string Title = Request.QueryString["Title"];

            Response.ClearContent();
            if (HttpContext.Current.Request.Browser.Browser != "IE")
            {
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + Title + ".url");
            }
            else
            {
                string sitename = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(Title + ".url"));
                Response.AddHeader("content-disposition", "attachment; filename=" + sitename);
            }
            Response.ContentType = "APPLICATION/OCTET-STREAM";
            Response.Write("[InternetShortcut]\r\n");
            Response.Write("URL=" + Url + "\r\n");
            Response.Write("IDList=\r\n");
            Response.Write("[{000214A0-0000-0000-C000-000000000046}]\r\n");
            Response.Write(" Prop3=19,2\r\n");
            Response.End();
        }

调用:location.href = "SetDesktop.aspx?url=" + window.location.href + "&Title=" + document.title;

posted @ 2011-08-09 15:07  Crazy Ma  阅读(580)  评论(0编辑  收藏  举报