使用C#,如何知道文件夹是否位于网络上
使用 C#,我希望我的应用程序返回文件夹(具有已知路径)是否位于网络中或我的计算机中。
我怎样才能做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用 C#,我希望我的应用程序返回文件夹(具有已知路径)是否位于网络中或我的计算机中。
我怎样才能做到这一点?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
如果您正在谈论映射的网络驱动器,则可以使用
DriveInfo
的DriveType
属性:If you are talking about a mapped network drive, you can use the
DriveInfo
'sDriveType
property:来自另一个SO问题的原始答案,检查路径是否在网络上。
使用 PathIsNetworkPath (pinvoke 参考):
Original Answer from another SO question, Check if path is on network.
Use PathIsNetworkPath (pinvoke reference):
根据@jgauffin 和@Daniel 的回答,你可以尝试这个小技巧:
Based on @jgauffin and @Daniel answers, you could try this little hack:
您可以使用以下方法获取文件夹的 UNC 路径。不完全是您正在寻找的内容,但可能有用
You can use folowing method to get UNC path for a folder. Not exactly what you are looking for but might be useful
请尝试 Shell 轻量级实用程序 API 中的以下操作:
需要考虑的事项:
Try the following from Shell Lightweight Utility API:
Things to take into consideration: