3

I need to trigger an URL to the browser control in my application. The URL contains a querystring of format DateTime.

Example : http://localhost:31401/WebSite4/PopUp.aspx?DateTime=12%2F10%2F2011+10%3A22%3A11

My problem here is that i have to remove the "/" (Slash) & ":"(Colon) in the date time and add "%2F" & "%3A" in place of these.

Example : 12/10/2011 10:22:11 should be converted to 12%2F10%2F2011+10%3A22%3A11

Is there any built-in method or way to do it? or Shall i have to replace them thorugh manual code?

3 Answers 3

8

Try this

 System.Web.HttpUtility.UrlEncode("12/10/2011 10:22:11")

Gives

 12%2f10%2f2011+10%3a22%3a11

You will need to add reference to System.Web.

Sign up to request clarification or add additional context in comments.

Comments

4

You can use HttpUtility.UrlEncode.

Comments

3

Try UrlEncode.

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

5 Comments

Decoding is not at all a problem. I've to encode it while sending it from my Standalone app to browser control.
You asked for a way to convert from "normal string" to "url string", which is what UrlEncode does. If you're looking for something else, I'm not sure I understand what. :)
Example : 12/10/2011 10:22:11 should be converted to 12%2F10%2F2011+10%3A22%3A11
Indeed. Amar Palsapure, whose answer you've accepted, has suggested the same thing as me, so I think it all will work out nicely in the end. Good luck!
You just have to make sure you convert the DateTime to a string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.