zoukankan      html  css  js  c++  java
  • 找不到网络名。 (Exception from HRESULT: 0x80070043)

    最近在客户电脑出现了一个怪异的报错,C# 打开保存文件对话框报如下错误:

    找不到网络名。 (Exception from HRESULT: 0x80070043) at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path)
    at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog)
    at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner)
    at Microsoft.Win32.CommonDialog.ShowDialog()

    是因为SaveFileDialog的InitialDirectory属性设置了相对路径导致的。

    经分析是客户在Mac电脑上,通过Parallels安装Win11虚拟机,导致访问桌面、我的文档等文件夹的时候,路径是:\\Mac\User\MyDocument,正常在Windows下的路径是:C:\Users\jinqi\Documents,为什么会这样呢,是因为这个平台创建的虚拟机将Mac的常用文件夹和虚拟机内的常用文件夹共享了,参考连接

    处理办法是在设置InitialDirectory的时候,判断路径是否为网络路径,如果是,就不设置值就行了。

    代码如下:

    SaveFileDialog dialog = new SaveFileDialog();
    string defaultPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    //mac虚拟机,win11的时候,桌面文件夹是:\\Mac\User\Desktop,这时候用InitialDirectory会异常
    if (!defaultPath.StartsWith("\\"))
    {
      dialog.InitialDirectory = defaultPath;
    }

  • 相关阅读:

    k
    通过类名调用类方法
    类Area的getArea方法是一个重载方法
    构造cry
    两个lader对象共享bottom
    向一个方法的基本数据类型参数传值
    Circle
    常量的用法
    显示本机时间
  • 原文地址:https://www.cnblogs.com/JqkAman/p/15693814.html
Copyright © 2011-2022 走看看