replacing space to %20 of url in vb.net

I am appending date time to URL which is in the format 7/14/2015 5:42:00. i need to convert space between date and time portion to %20

how to do it.  

One wary may be appending date and time separately with %20 in between.

is there any better way to do it  in vb.net
vensaliAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel Van Der WerkenIndependent ConsultantCommented:
Use the HttpUtility.UrlEncode() method.
it_saigeDeveloperCommented:
If you want to encode the entire url then Dan7el provides a good method, however, if you want to encode just the path portion, then you would use HttpUtility.UrlPathEncode().

That being said, however, in my testing UrlPathEncode is a tad buggy (probably why Microsoft recommends just using UrlEncode:
Capture.JPG

My real recommendation would be to use the Uri.EscapeUriString() method to encode only the path and query portion of the Url.  To encode the full Url, I would recommend the Uri.EscapeDataString().

Proof of concept:
Imports System.Web

Module Module1
	Sub Main()
		Dim url = "http://www.yoursite.com/index.aspx?val1=Value 1&val2=Value 2&dt=7/14/2015 5:42:00"
		Console.WriteLine("Url before encoding: {0}", url)
		Console.WriteLine()
		Console.WriteLine("Url after encoding: {0}", HttpUtility.UrlEncode(url))
		Console.WriteLine()
		Console.WriteLine("Url after encoding: {0}", HttpUtility.UrlPathEncode(url))
		Console.WriteLine()
		Console.WriteLine("Url after uri escapedatastring: {0}", Uri.EscapeDataString(url))
		Console.WriteLine()
		Console.WriteLine("Url after uri escapeuristring: {0}", Uri.EscapeUriString(url))
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.