检查路径是在网络 [英] Check if path is on network

查看:139
本文介绍了检查路径是在网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

  1. 在当前选择的文件夹是一个网络 - (通过映射驱动器( I:\备份)或UNC符号( \\服务器2 \备份))
  2. 在当前选择的文件夹是一个不同的物理磁盘比数据库文件夹
  1. When selected folder is on a network
    (either by a mapped drive (I:\Backup) or UNC notation(\\server2\backup))
  2. 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"));
    }
}

这篇关于检查路径是在网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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