0

I am making a treeview, I want to open a file on clicking the file node of treeview directory. What I did here as:

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);

        }  

Unfortunately when I check the html, it is rendered as bellow: href="file:///D:/Training%2520Sessions/Enterprise%2520Portal/Zeeshan%2520H%2520Jafry%2520EP%2520session%2520-%2520Jul%252018%25202011%252006.39.15%2520PM.wmv"

the directory is local so I am unable to access this. What is the workaround of this problem please.

Shankar Das
  • 117
  • 1
  • 4
  • 14

1 Answers1

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).

Community
  • 1
  • 1
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • Basically my requirement is to use the absolute path rather than relative path. I only want the path to be rendered in format like: href="D:\Training Sessions\Enterprise Portal\Zeeshan H Jafry EP session - Jul 18 2011 06.39.15 PM.wmv", then it should work i think!! – Shankar Das Sep 26 '12 at 15:19
  • No, that won't work; you can't transmit files over HTTP using links with a FILE protocol. You will need to construct the path to be a URL which ultimately points to that file and the server handler map it to the local file system for download. – Grant Thomas Sep 26 '12 at 15:21
  • Thanks Grant, that is the problem actually I don't want to link with a File protocol. I have tested a simple html link like: – Shankar Das Sep 26 '12 at 15:25