Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

Get Current File and QueryString

Hi All,

Is there a piece of C# code that will return the file and any strings appended to the file from a URL?

e.g. http://www.mydomain.com/page.aspx?account=220&type=334

In my page.aspx code, I need to obtain this part of the URL:

page.aspx?account=220&type=334

Many Thanks,

Rit
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image


string url = @"http://www.mydomain.com/page.aspx?account=220&type=334";
string exp = @"http.*/";
Regex reg = new Regex(exp);
string ret = reg.Replace(url, string.Empty);
MessageBox.Show(ret);

Open in new window

String str_main = " http://www.mydomain.com/page.aspx?account=220&type=334"

Dim str_result as string

str_reult

string strMain =  " http://www.mydomain.com/page.aspx?account=220&type=334";
int len = strMain.Length;        
string ResultString = "";

ResultString = strMain.SubString(strMain.IndexOf("?")+1 , len)

Please disregard my last thread


here is the currect

string strMain =  " http://www.mydomain.com/page.aspx?account=220&type=334";
int len = strMain.Length;        
string ResultString = "";

ResultString = strMain.SubString(strMain.IndexOf("?")+1 , len) ;
Avatar of Luis Pérez
I guess you need to apply to any url (detecting your current url), so you need:

String url = Request.Url.ToString().Replace("http://www.", "");

Hope that helps.
ASKER CERTIFIED SOLUTION
Avatar of masterpass
masterpass
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

url.SubString(url.LastIndexOf("/")+1)
a fix

url.Substring(url.LastIndexOf("/")+1)
Avatar of rito1
rito1

ASKER

Wow, I go to lunch and come back to many answers.. thank you very much.

I am just working through them now and will come back to you.

Kind Regards,

Rit
Avatar of rito1

ASKER

Perfect, thanks,

Rit