encode url string C#

Posted on 2011-10-20
Last Modified: 2012-06-22
How do i use Server.UrlEncode to firstly remove a '~' and add additional text to the URL? using C#
Question by:Pixie_IT
    LVL 9

    Expert Comment

    not clear about you question
    some thing like this would work
    String MyURL;
    MyURL = "" + Server.UrlEncode("samples~".Replace("~", "additional text"));
    Response.Write("<a href=" + MyURL + "> samples </a>");

    Open in new window


    Expert Comment

    String MyURL;
    MyURL = "" + Server.UrlEncode("ASP.NET Examples");

    Response.Write("<a href=" + MyURL + "> ASP.NET Examples </a>");
    LVL 14

    Expert Comment

    by:nishant joshi
    string url=System.Web.HttpUtility.UrlDecode("http:\\") + "Append something something";

    Accepted Solution

    The answer we were looking for we eventually found and was:
    //Getting the current context of HTTP request
            var context = HttpContext.Current;

            //Checking the current context content
            if (context == null) return null;

            //Formatting the fully qualified website url/name
            var appPath = string.Format("{0}://{1}{2}{3}",
                                        context.Request.Url.Port == 80
                                            ? string.Empty
                                            : ":" + context.Request.Url.Port,

    Author Closing Comment

    Unfortunately the wording of the question may have resulted in not gettign the answer we required.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now