检查路径是在网络是在、路径、网络

2023-09-02 10:51:20 作者:荒凉如歌

在我的应用程序我有一个对话框,用户可以从中选择一个数据库备份位置。 我想提醒用户,如果他/她选择的位置是可能不安全。

In my app I have a dialog in which the user can select a database backup location. I want to warn the user if the location he/she selected is "probably not secure".

我要考虑以下地点的安全:

I want to consider the following locations secure:

在当前选择的文件夹是一个网络 - (通过映射驱动器( I:备份)或UNC符号( \服务器2 备份)) 在当前选择的文件夹是一个不同的物理磁盘比数据库文件夹 When selected folder is on a network (either by a mapped drive (I:Backup) or UNC notation(\server2backup)) When selected folder is on a different physical disk than the database folder

我怎样才能得到这样的有关选定文件夹信息? 我知道关于 DriveInfo 类,但它只能处理驱动器号,而不是UNC路径。

How can I get this kind of info about a selected folder? I know about the DriveInfo class, but it only handles drive letters, not UNC paths.

推荐答案

看看的的 PathIsNetworkPath 功能:

class Program
{
    [DllImport("shlwapi.dll")]
    private static extern bool PathIsNetworkPath(string pszPath);

    static void Main(string[] args)
    {
        Console.WriteLine(PathIsNetworkPath("i:Backup"));
    }
}