Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 22, 2012 04:24 AM by tej narayan
Member
28 Points
35 Posts
Feb 21, 2012 03:37 PM|LINK
Hi,
I want to know how to retrieve data from URL.
Ex: http://localhost:0003/index.aspx#access_token=qwqwqwqwqw
How to get access_token value from this URL.
Star
9337 Points
1447 Posts
Feb 21, 2012 04:03 PM|LINK
there is nothing like "#" in http://localhost:0003/index.aspx#access_token=qwqwqwqwqw
that got to be "?" so it becomes http://localhost:0003/index.aspx?access_token=qwqwqwqwqw
that is what you call querystring and you can access it on index page like this:
string qstring = Request.QueryString["access_token"]; //C#
Dim qstring as string = Request.QueryString("access_token") //VB
More info:
http://www.dotnetperls.com/querystring
http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString
All-Star
18223 Points
2725 Posts
Feb 21, 2012 04:11 PM|LINK
The # sign is not passed over to the server side. So you can not directly get it in code behind. There is a work around using jQuery/JavaScript where you receive it in client side and set it on a server side control and send to server.
See the following link for the example:
http://stackoverflow.com/questions/317760/how-to-get-url-hash-from-server-side
20143 Points
3327 Posts
Feb 21, 2012 04:14 PM|LINK
Generally the QueryString format will be like this!
http://www.google.com/q=helloword
which the above QueryString can be retrieved through Request.QueryString["q"]!
If you wan to retrieve values from your URL, then write custom logic to do that!
Check the sample code below!
string strURL = Request.Url.ToString(); string[] strQueryString = strURL.Split(new char[]{'#'}); foreach (string item in strQueryString) { string[] strQueryValues = item.Split(new char[]{'='}); string strKey = strQueryValues[0]; string strValue = strQueryValues[1]; }
Hope it helps u...
194 Points
69 Posts
Feb 22, 2012 04:24 AM|LINK
using System.IO;
using system.Net;
WebClient client = new WebClient(); string htmlCode = client.DownloadString(http://localhost:0003/index.aspx#access_token=qwqwqwqwqw);
uisng the above code you will get data from that site in string format and then you can manipulate by removing html tables
by using c# functions like replace() or remove or any other metgod to get data
I have tried this in my page and is working fine
bihariagrawa...
Member
28 Points
35 Posts
How to retrieve data from URI.
Feb 21, 2012 03:37 PM|LINK
Hi,
I want to know how to retrieve data from URL.
Ex: http://localhost:0003/index.aspx#access_token=qwqwqwqwqw
How to get access_token value from this URL.
me_ritz
Star
9337 Points
1447 Posts
Re: How to retrieve data from URI.
Feb 21, 2012 04:03 PM|LINK
there is nothing like "#" in http://localhost:0003/index.aspx#access_token=qwqwqwqwqw
that got to be "?" so it becomes http://localhost:0003/index.aspx?access_token=qwqwqwqwqw
that is what you call querystring and you can access it on index page like this:
string qstring = Request.QueryString["access_token"]; //C#
Dim qstring as string = Request.QueryString("access_token") //VB
More info:
http://www.dotnetperls.com/querystring
http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString
adeelehsan
All-Star
18223 Points
2725 Posts
Re: How to retrieve data from URI.
Feb 21, 2012 04:11 PM|LINK
The # sign is not passed over to the server side. So you can not directly get it in code behind. There is a work around using jQuery/JavaScript where you receive it in client side and set it on a server side control and send to server.
See the following link for the example:
http://stackoverflow.com/questions/317760/how-to-get-url-hash-from-server-side
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
roopeshreddy
All-Star
20143 Points
3327 Posts
Re: How to retrieve data from URI.
Feb 21, 2012 04:14 PM|LINK
Hi,
Generally the QueryString format will be like this!
http://www.google.com/q=helloword
which the above QueryString can be retrieved through Request.QueryString["q"]!
If you wan to retrieve values from your URL, then write custom logic to do that!
Check the sample code below!
string strURL = Request.Url.ToString(); string[] strQueryString = strURL.Split(new char[]{'#'}); foreach (string item in strQueryString) { string[] strQueryValues = item.Split(new char[]{'='}); string strKey = strQueryValues[0]; string strValue = strQueryValues[1]; }Hope it helps u...
Roopesh Reddy C
Roopesh's Space
tej narayan
Member
194 Points
69 Posts
Re: How to retrieve data from URI.
Feb 22, 2012 04:24 AM|LINK
using System.IO;
using system.Net;
WebClient client = new WebClient();
string htmlCode = client.DownloadString(http://localhost:0003/index.aspx#access_token=qwqwqwqwqw);
uisng the above code you will get data from that site in string format and then you can manipulate by removing html tables
by using c# functions like replace() or remove or any other metgod to get data
I have tried this in my page and is working fine