Hi i would like to check if a property exists?
This is my code
string abpath=null;
var hc= HttpContext.Current.Request.UrlReferrer;
if (hc.AbsolutePath !=null)
{
var _temp = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
abpath = _temp.ToString();
}
I would like to Find out if AbsolutePath exists
can any one help me how to check.
right now it throws error as AbsolutePath doesn’t exists to check
Thanks for your time
First you have to map the absolute path (url) to a local file system path. Then you can check whether the file exists:
Update:
I guess I misunderstood the question. The problem is, that if your page/action/etc is called directly (e.g. by entering its URL in the browser), then there is no Referrer (previous page). So you have to first check
Request.UrlReferrerfor null:BTW: since AbsolutePath is already a string, there is no need to call
ToString()on it. So you can simplify your code some more: