如何在下拉列表中列出本地驱动器? [英] How to list the local drives in dropdown ?

查看:132
本文介绍了如何在下拉列表中列出本地驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,下拉列表应列出本地计算机中的所有驱动器。



以下是代码: -

---- ----------------

 ddlDrives.Items.Clear(); 
ddlDrives.Items.Add( - 选择 - );
foreach 字符串 objDrive in Directory.GetLogicalDrives())
{
ddlDrives.Items.Add(objDrive);
}



但是如果它托管在服务器中,它显示服务器驱动器。我只想在下拉列表中显示用户的本地系统驱动器。我该怎么办?

解决方案

ASP.NET是服务器端编程语言,您无法从服务器端控制本地文件系统。您需要尝试使用客户端编程语言之一,例如javascript,但这些语言可能没有这种级别的功能来访问文件系统,用户也可以阻止或限制从浏览器执行此类脚本。



检查使用JavaScript查找文件 [ ^ ]


使用ASP.NET并不容易。请参阅: https://social.msdn.microsoft.com/Forums/vstudio/en-US/fa5ce738-47ef-4e41-9f9c-a703cd4f08c1/how-to-get -list-of-drive-on-local-system-using-aspnet?forum = csharpgeneral [ ^

http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/20/how-can-i-dynamically-show-available-drive - 字母-IN-A一览box.aspx

In my project the dropdown should list all drives in local computer.

Here is the code: -
--------------------

ddlDrives.Items.Clear();
ddlDrives.Items.Add("-Select-");
foreach (string objDrive in Directory.GetLogicalDrives())
{
     ddlDrives.Items.Add(objDrive);
}


But if It hosted in server ,Its showing server drives.I just want to show the User's Local system drives in dropdown .What Should I do?

解决方案

ASP.NET is server side programming language and you don't have control over local file system from server side. You need to try with one of client side programming language like javascript but those languages may not have such level of capabilities to access file system and also users can block or limit executing such scripts from their browser.

check Find files with JavaScript[^]


Using ASP.NET is not so easy. Please see: https://social.msdn.microsoft.com/Forums/vstudio/en-US/fa5ce738-47ef-4e41-9f9c-a703cd4f08c1/how-to-get-list-of-drives-on-local-system-using-aspnet?forum=csharpgeneral[^]


http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/20/how-can-i-dynamically-show-available-drive-letters-in-a-list-box.aspx


这篇关于如何在下拉列表中列出本地驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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