使用C#Windows应用程序从未知根目录中查找文件夹中的文件 [英] finding files in a folder from an unknown root directory using c# windows application
本文介绍了使用C#Windows应用程序从未知根目录中查找文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好...
如果我知道未知根目录的文件夹名称,那么如何从C#Windows应用程序访问该文件夹中的文件.请给我一个答案..
在此先感谢.
Hi all...
If I know the folder name of an unknown root directory, then how can I access the files in that folder from a C# windows application. Please give me an answer..
Thanks in Advance.
推荐答案
没有未知根目录"之类的东西.您总会有一些根:系统上每个卷的根.您可以使用System.IO.DriveInfo.GetDrives
获取所有逻辑驱动器,并使用System.IO.DriveInfo.GetDrives.RootDirectory
获取每个逻辑驱动器的根目录,请参见:
http://msdn.microsoft.com/en-us/library/system. io.driveinfo.getdrives.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. io.driveinfo.rootdirectory.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.io. directoryinfo.aspx [ ^ ].
现在,让我告诉您对于ASP.NET而言,这根本没有任何意义.您要在哪里搜索目录?在客户端? Web应用程序无权访问客户端.在服务器端? Web应用程序只能访问相对于站点根目录的目录.
因此,在服务器端,您的真实根目录是作为Server.MapPath("~/");
返回的根目录,请参阅:
http://msdn.microsoft.com/en-us/library/ms178116.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. web.httpserverutility.mappath.aspx [ ^ ].
您无能为力. 您的Web应用程序无法访问任何其他内容.
—SA
There is no such thing as "Unknown root directory". You always have some root: the root of each volume on the system. You can get all logical drives usingSystem.IO.DriveInfo.GetDrives
and the root directory of each usingSystem.IO.DriveInfo.GetDrives.RootDirectory
, please see:
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.rootdirectory.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx[^].
Now, let me tell you that for ASP.NET it makes no sense at all, anyway. Where do you want to search for directory? On client side? A Web application does not have access to the client side. On server side? A Web application can access only the directories relative to the root path of the site.
So, on the server side, your real root is the one returned asServer.MapPath("~/");
please see:
http://msdn.microsoft.com/en-us/library/ms178116.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^].
There is nothing else you can do. Anything else is not accessible by your Web application.
—SA
这篇关于使用C#Windows应用程序从未知根目录中查找文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文