Monday, November 30, 2009

Path from where a user control was loaded (ASCX)

Here is the code to retreive the path from where a user control (ASCX) was loaded.

protected string GetLoadDirectory()
{
    string controlPath = this.ResolveUrl(this.AppRelativeVirtualPath);
    if (string.IsNullOrEmpty(controlPath) == false)
    {
        int indexOfLastSlash = controlPath.LastIndexOf("/");
        controlPath = controlPath.Substring(0, indexOfLastSlash + 1);
    }
    return controlPath;
}

No comments:

Post a Comment

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.