Reputation: 3022
in my user control i have HyperLink the link need to be to page named "export.ashx" in the same folder of the page that cotaines the user contrl
<asp:HyperLink CssClass="btnblue" ID="hypAddItem" Visible="false" NavigateUrl="" runat="server"><i class="icon-plus"></i> Add Part</asp:HyperLink>
and in my Code
hypAddItem.NavigateUrl = pageUrl + "Export.ashx";
what i need to put in the pageUrl that will work on each folder?
My directory structure
root
folder1
pageWithUC.aspx
export.ashx
folder2
pagewithUC.aspx
export.ashx
usercontrols
uc.acsx
Upvotes: 0
Views: 2429
Reputation: 1146
You can do this:
var url = Request.Url.FilePath;
var folder = System.IO.Path.GetDirectoryName(url)
hypAddItem.NavigateUrl = folder + "/Export.ashx";
Upvotes: 0
Reputation: 20693
You can get current URL from request and combine it with your ashx, like this :
Uri myUri = new Uri(HttpContext.Current.Request.Url, "Export.ashx");
then use Uri class methods to get relative path :
hypAddItem.NavigateUrl = myUri.PathAndQuery;
Upvotes: 0
Reputation: 4596
You can try with Server.MapPath(~) and use then folder along with it
Upvotes: 0
Reputation: 5600
Do this:
~/folder1/export.ashx
and if you want the second folder:
~/folder2/export.ashx
~
sign stands for your root direcotry.
you can also go back one directory, from uc.acsx, and go inside folder1/folder2:
../folder1/export.ashx
Upvotes: 2