如何使用指定的关键字在ASP.NET中显示来自Web服务器的文件列表 [英] How to display list of a file from a Web server in ASP.NET using a specified key word

查看:104
本文介绍了如何使用指定的关键字在ASP.NET中显示来自Web服务器的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

i need to display list of files from remote server which has the keyword i specify in a textbox. and also need to see that file when double cliked on it.
which control should i use to display the list...if i use listbox, i think there is no double click event.
i tried the below code :-







string filename = TextBox1.Text;
        if (File.Exists(Server.MapPath("files/" + (filename))))
        {
            Response.Write("file exist");
            ListBox1.Items.Add(filename);

        }
        else
        {
            Response.Write("no");
        }




这里的文件是文件夹名称,
上面仅显示单个文件,并且仅在输入完整名称时显示.


谁能帮我...
在此先感谢...




here file is the folder name,
the above shows only single file, and it is displayed only when the complete name is inputed.


can any one help me...
thanks in advance...

推荐答案



如果可以的话请尝试...

Hi,

Try this if could help...

var targetDir = Server.MapPath("./files/");
string[] files = Directory.GetFiles(targetDir);
if (files.Length > 0)
try
{
    foreach (string file in files)
    {
       ListBox1.Items.Add(file);
    }
}
catch (FileNotFoundException)
{
   // Catch erro here?....
}



请帮忙投票 ...

问候



Please do not forget to vote if could help...

Regards,


这篇关于如何使用指定的关键字在ASP.NET中显示来自Web服务器的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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