WEB网页上下载快捷方式到本地

js代码:

View Code
   //下载桌面图标

        function returnDown() {

            var CompanyName = "xxxxxxxx";

            var ProductNikeName = "xxxxxxxx";

            var Favicon = "a/favicon.ico";   //一定要是 网站根目录下的ico图标

            var browserType = "MSIE";

            if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {

                browserType = "Firefox";

            }

            if (CompanyName.length == 0) {

                return;

            } else if (ProductNikeName.length == 0) {

                return;

            } else {

                window.open("bs/down_shortcut.aspx?CompanyName=" + unicode(CompanyName) + "&ProductNikeName=" + ProductNikeName + "&baseurl=" + window.location.host + "/&url=" + window.location + "&browserType=" + browserType + "&Favicon=" + Favicon);

            }

        }

down_shortcut.aspx 代码:

View Code
///   <summary> 

    ///   文件下载 

    ///   </summary> 

    ///   <param   name= "FullFileName "> </param> 

    private void FileDownload(string FileName, string browserType)

    {

        try

        {

            if (!File.Exists(Server.MapPath(FileName)))

            {

                return;

            }

            else

            {

                string filePath = Server.MapPath(FileName);//路径

                //以字符流的形式下载文件 

                FileStream fs = new FileStream(filePath, FileMode.Open);

                byte[] bytes = new byte[(int)fs.Length];

                fs.Read(bytes, 0, bytes.Length);

                fs.Close();

                string FileNameUrl = FileName;

                if (FileName.IndexOf(".link") > -1)

                    FileNameUrl = FileName.Split('.')[0] + ".url";

                Response.ContentType = "application/octet-stream";

                //通知浏览器下载文件而不是打开 

                if (browserType == "Firefox")

                    Response.AddHeader("Content-Disposition", "attachment; filename=" + (FileNameUrl));

                else

                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileNameUrl, System.Text.Encoding.UTF8));

                Response.BinaryWrite(bytes);

                Response.Flush();

                Response.End();

            }

        }

        catch { return; }



    }

    /// <summary>

    /// 生成快捷方式文件

    /// </summary>

    /// <param></param>

    /// <param></param>

    /// <returns></returns>

    private bool createFile(string FileName, string strurl, string baseurl, string Favicon)

    {

        try

        {

            if (File.Exists(Server.MapPath(FileName)))

            {

                return true;

            }

            else

            {

                FileStream fs = new FileStream(Server.MapPath(FileName), FileMode.CreateNew);

                StreamWriter sw = new StreamWriter(fs);

                sw.WriteLine("[DEFAULT]");

                sw.WriteLine("BASEURL=http://" + baseurl);

                sw.WriteLine("[InternetShortcut]");

                sw.WriteLine("URL=" + strurl);

                sw.WriteLine("IDList=");

                sw.WriteLine("IconFile=http://" + baseurl + Favicon);

                sw.WriteLine("IconIndex=1");

                sw.WriteLine("[{000214A0-0000-0000-C000-000000000046}]");

                sw.WriteLine("Prop3=19,2");

                sw.Close();

                fs.Close();

                return true;

            }

        }

        catch (Exception ex)

        {

            return false;

        }

    }

 

 

你可能感兴趣的:(Web)