我有一个文件树视图,我需要从另一个页面下载这些文件。 所以我将NavigateUrl设置为下载页面,但我获取当前页面路径和下载页面路径。
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);
}
当我点击它导航到
的节点时http://localhost/_CONTROLTEMPLATES/MyLib/_layouts/Download.aspx?file=c:Somefile.txt
但我想要的是这样的根URL的路径。
http://localhost/_layouts/Download.aspx?file=ownload.aspx?file=c:Somefile.txt
我不想将我的download.aspx移动到该位置。 有人为此得到了很好的解决方案吗?
答案 0 :(得分:0)
我找到了我想要的简单解决方案,而不是
nodeFile.NavigateUrl = "_layouts/Download.aspx?file="+file.FullName;
我在路径的开头加了一个“/”
nodeFile.NavigateUrl = "/_layouts/Download.aspx?file="+file.FullName;
答案 1 :(得分:0)
您的解决方案仅适用于WebAppliction根目录下的网站集。
我建议使用SPUtility.GetServerRelativeUrlFromPrefixedUrl method
来计算实际正确的网址。
如果要在SPWeb级别定位应用程序页面,请使用:
var theUrl = SPUtility.GetServerRelativeUrlFromPrefixedUrl(
"~site/_layouts/Download.aspx?file="+file.FullName
);
如果您想要在SPSite级别定位应用程序页面,请使用:
var theUrl = SPUtility.GetServerRelativeUrlFromPrefixedUrl(
"~sitecollection/_layouts/Download.aspx?file="+file.FullName
);
这将确保代码运行的网址的正确性。
作为旁注,您可以访问SharePoint dedicated StackExchange site