0

我正在制作一个树视图,我想在单击树视图目录的文件节点时打开一个文件。我在这里做了什么:

foreach (FileInfo File in currentDir.GetFiles())
        {
            TreeNode node = new TreeNode(File.Name, File.FullName);
            node.SelectAction = TreeNodeSelectAction.SelectExpand;
            node.PopulateOnDemand = false;
            node.NavigateUrl = ResolveClientUrl(File.FullName); 
            node.ChildNodes.Add(node);
            currentNode.ChildNodes.Add(node);

        }  

不幸的是,当我检查 html 时,它呈现如下: href="file:///D:/Training%2520Sessions/Enterprise%2520Portal/Zeeshan%2520H%2520Jafry%2520EP%2520session%2520-%2520Jul%252018%25202011 %252006.39.15%2520PM.wmv"

该目录是本地的,所以我无法访问它。请问这个问题的解决方法是什么。

4

1 回答 1

0

Firstly the contents of the directory must be available other than only locally - for instance, within a directory under the root of your website as set up in IIS, or a virtual directory somewhere.

Secondly you can't serve files through web pages with absolute local paths - you will need to make these URLs relative to the domain of the website.

So, the principle is to take an absolute path and 'map' it to a virtual path, or URL, the answer to that question is answered all over the place and here's one for example.

ResolveClientUrl won't work in this case because...

The URL returned by this method is relative to the folder containing the source file in which the control is instantiated.

and it looks like your files are just in some arbitrary directory (as far as the web application is concerned).

You have the information that you need to do this, with the knowledge of where this stuff resides and the application exposes knowledge of where it itself resides (for instance, with the ApplicationPath of the request context, and so on).

于 2012-09-26T15:06:17.787 回答