Click here to Skip to main content
11,927,711 members (52,101 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked

Create Internet Shortcut

, 3 Jul 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to create an internet shortcut


Did you ever get such a requirement to create the shortcut of your website with query string? Also, user should be able to create the shortcut of website from the page itself. User just needs one button click to have his/her shortcut URL ready on his/her desktop.

It is very easy to create the shortcut through Microsoft's built in utility. At the same time, it is somewhat tricky to create the shortcut of your URL through your website only. As you know, you can't create a shortcut on Client's machine due to security concerns through any web page.

In this article, I will show you how to create a shortcut file and save/download it using Jquery. I have tried my best to provide clean code with comments.

Using the Code

  1. Create one empty website.
  2. Add default page.
  3. Add the below jquery files:
    1. jquery-1.7.1.min
    2. json2-min


<html xmlns="">
<head runat="server">
    <script src="js/json2-min.js"></script>
    <script src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        function GenerateShortCut() {
            var params = new Object();
            params.url = '<%= Request.Url %>';

                        url: "Default.aspx/GenerateShortCut",
                        data: JSON.stringify(params), // For empty input data use "{}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function () { document.getElementById('<%= btnDownload.ClientID %>').click(); },
                        failure: function () { }
    <form id="form1" runat="server">
            <input type="button" value="Create Shortcut" onclick="GenerateShortCut();" />
            <div style="display:none">
                <asp:Button ID="btnDownload" runat="server" />


using System;
using System.IO;
using System.Web;
using System.Web.Services;

public partial class Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        btnDownload.Click += btnDownload_Click;

    /// <summary>
    /// Download Event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void btnDownload_Click(object sender, EventArgs e)
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        "attachment; filename=test.url"); //Change the file name as per your requirement
        (HttpContext.Current.Server.MapPath("~/Temp/test.url")); //Change the file name as per your requirement

    /// <summary>
    /// Generate the short cut file and store it in temp folder
    /// </summary>
    /// <param name="url"></param>
    /// <returns></returns>
    public static string GenerateShortCut(string url)
            // IconFile = URL of favicon.ico file
            string[] lines = { "[InternetShortcut]", "URL=" + url, 
            "IconFile=", "IconIndex=0" };

            //If file exists then delete the old "speedtest.url" file
            if (File.Exists(HttpContext.Current.Server.MapPath("").ToString() + 
            "\\temp\\test.url")) //Change the file name as per your requirement
                File.Delete(HttpContext.Current.Server.MapPath("").ToString() + 
                "\\temp\\test.url"); //Change the file name as per your requirement

            using (System.IO.StreamWriter file = new System.IO.StreamWriter
               ((HttpContext.Current.Server.MapPath("").ToString() + 
               "\\Temp\\test.url"))) //Change the file name as per your requirement
                foreach (string line in lines)
        catch (Exception ex)
        return "";


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Narotam Gediya
Team Leader
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Generalinteresting! Pin
Brian A Stephens18-Jul-14 8:52
professionalBrian A Stephens18-Jul-14 8:52 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun3-Jul-14 3:26
memberHumayun Kabir Mamun3-Jul-14 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 3 Jul 2014
Article Copyright 2014 by Narotam Gediya
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid