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: