I found the simple soulution i was looking for insted of
nodeFile.NavigateUrl = "_layouts/Download.aspx?file="+file.FullName;
I put an "/" in the beginning of the path
nodeFile.NavigateUrl = "/_layouts/Download.aspx?file="+file.FullName;
Вопрос
I have a treeview of files and i need to download those files from another page. So Im setting the NavigateUrl to the downloadpage but im getting the currentpage path and downloadpages path.
foreach (FileInfo file in currentDir.GetFiles())
{
TreeNode nodeFile = new TreeNode(file.Name, file.FullName);
nodeFile.NavigateUrl = "_layouts/Download.aspx?file="+file.FullName;
nodeFile.Target = "_blank";
nodeFile.ImageUrl = "_layouts/images/DOC_SP16.gif";
currentNode.ChildNodes.Add(nodeFile);
}
When i click the node it's navigating to
http://localhost/_CONTROLTEMPLATES/MyLib/_layouts/Download.aspx?file=c:Somefile.txt
but what i want is the path to the root URL like this.
http://localhost/_layouts/Download.aspx?file=ownload.aspx?file=c:Somefile.txt
I don't want to move my download.aspx to that location. Anybody got a good solution for this?
Решение
I found the simple soulution i was looking for insted of
nodeFile.NavigateUrl = "_layouts/Download.aspx?file="+file.FullName;
I put an "/" in the beginning of the path
nodeFile.NavigateUrl = "/_layouts/Download.aspx?file="+file.FullName;
Другие советы
Your solution will only work on site collection that are on the root of a WebAppliction.
I suggest to use the SPUtility.GetServerRelativeUrlFromPrefixedUrl method
to calculate the actual correct url.
If you want to target an application page at SPWeb level, use:
var theUrl = SPUtility.GetServerRelativeUrlFromPrefixedUrl(
"~site/_layouts/Download.aspx?file="+file.FullName
);
If you want to target an application page at SPSite level, use:
var theUrl = SPUtility.GetServerRelativeUrlFromPrefixedUrl(
"~sitecollection/_layouts/Download.aspx?file="+file.FullName
);
This will ensure the correctness of the url, wherever your code runs.
As a side note, you may visit the SharePoint dedicated StackExchange site