UrlPathEncode UrlPathEncode

Where to use UrlPathEncode? In you can encode the URL to avoid breaking of the request. Here we will see how to do web page path encoding.

HttpUtility.UrlEncode("My Path") returns out put as My+Path. You can see it replaces the space to +. However, HttpUtility.UrlPathEncode("My Path") returns My%20Path. Here space gets converted into %20.

If you are having space or nay other special character in web page path. Don't forget to use UrlPathEncode. UrlPathEncode Example.
using System;
using System.Web;

public partial class URLEncodeDemo : System.Web.UI.Page
  protected void Page_Load(object sender, EventArgs e)
    string filepath = "Monthly Reports 01 12 2012.csv";

    string url = "" + HttpUtility.UrlPathEncode(filepath);


} UrlPathEncode example.
Imports System
Imports System.Web

Public Partial Class URLEncodeDemo
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(sender As Object, e As EventArgs)
		Dim filepath As String = "Monthly Reports 01 12 2012.csv"

		Dim url As String = "" + HttpUtility.UrlPathEncode(filepath)


	End Sub
End Class

Tags: Interview Questions for 2 years or 3 years experianceasp net image 2.0 step by step Membership Provider File HandlingWhat is web garden in open new Convert String To Convert Image To Base64Hack asp.netListBox Binding How To Write a Cookie and Read


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.