I created a Tree View out of a file system in ASP.NET. When the user clicks on a file tree node I want the file to either open (if the browser can open it) or download. In my code the files are actually written as anchor tags:
for (int ctr = 0, cnt = filesInDirectory.Length; ctr < cnt; ctr++)
{
TreeNode newNode = new TreeNode(filesInDirectory[ctr].Name, filesInDirectory[ctr].FullName);
newNode.Text = "<a href=" + StringToURL(filesInDirectory[ctr].FullName) + ">" + filesInDirectory[ctr].Name + "</a>";
baseNode.ChildNodes.Add(newNode);
}
This work in creating the anchor tags, but when I click on a tag nothing happens. If I right-click and save the link, then paste it into the URL it works fine. How do I enable left clicking?
FIXED:
Your code worked after I added “http:” to the front of the file path. Thank you!
Try using the NavigateUrl property of the TreeNode to provide the target link.