无法使超链接在c#.net的目录列表中工作 [英] Can't get the Hyperlink to work in Directory listing in c#.net

查看:45
本文介绍了无法使超链接在c#.net的目录列表中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在列出网页中目录中的所有文件.
我已经成功完成了.
现在,我想从网页中打开文件,但无法执行此操作.
我的代码如下:

Hi,

I am listing all the files from directory in a web page.
I have done it successfully.
Now I want to open the files from webpage but I am unable to do this.
My code is below:

DirectoryInfo directory = new DirectoryInfo("C:/files/");
                FileSystemInfo[] files = directory.GetFiles("*.txt");
                var OrderedFiles = files.OrderByDescending(f => f.Name);
                foreach (FileSystemInfo file in OrderedFiles)
                {
                    var link = new HyperLink { };
                    link.NavigateUrl = "C:/files/" + file.Name;
                    link.Text =    file.Name    ;

                    Panel1.Controls.Add(link);




在此先感谢




Thanks in advance

推荐答案

奇怪:昨天只好敲了这样的话:

使用HtmlAnchor控件而不是HyperLink控件:

Weird: just had to knock something like this up yesterday:

Use an HtmlAnchor control as opposed to a HyperLink control:

link = new HtmlAnchor();
link.HRef = ResolveUrl(path + "\\" + file.Name);
link.Target = "_blank";
link.InnerText = file.Name;



路径可能是这样的:

@"~\Reports\Documents";



where path might be like:

@"~\Reports\Documents";


数字人说了.

但这可能只是一个小错误.就像您应该将@符号放在具有/符号或\\符号的字符串之前
Digital man said it.

But it might just be a small error. Like you should put the @ sign before your strings that have / sign or \\ sign


这篇关于无法使超链接在c#.net的目录列表中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆