【问题标题】:C# Create Shortcut Icon Location is not working for network pathsC# 创建快捷方式图标位置不适用于网络路径
【发布时间】:2014-11-25 05:36:00
【问题描述】:

我正在使用 IwishRuntime 库来动态创建快捷方式。如果图标位于网络路径中,则设置图标位置将不起作用。

例如,如果路径类似于“\\ServerName\Folder\Resources\Userguide.ico”;不会设置图标。 这只发生在 Windows 8 和 8.1 中。它在以前的操作系统中运行良好。

有没有办法解决这个问题。

            string path = System.IO.Directory.GetCurrentDirectory() + @"\Upgrade\Resources\userguide.ico";
            //Icon Location is set only if the file is there. If the file is not accessible due to security reasons 
            //Icon location is not set. The default program will be taken as the icon in this case.
            if (System.IO.File.Exists(path))
            {
                shortcut.IconLocation = path;
            }

谢谢。

【问题讨论】:

  • 您的网络路径应该以两个斜杠 ("\\ServerName\Folder...") 开头,还是拼写错误?否则它可能是一个许可的事情。尝试在同一目录中放置一个随机文本文件并读取它。
  • 不,这是一个错字。它以 \\ServerName 开头。事实上,它从 Directory.GetCurrentDirectory() 中读取。所以它返回正确的值。也没有权限问题。我检查了那个。它不适用于以“\\”开头的网络路径。即使对于我自己的机器,如果我将路径作为网络路径 - \\Tharindu\Share\Resources\userguide.ico 它也不起作用。但是,如果我将路径指定为 D:\\...etc 它将起作用。

标签: c# icons shortcut


【解决方案1】:

您需要在您的路径前使用 @ 并且每次都使用 \\

@"\\Network\\ExampleFolder"

它在 Windows 10 上运行

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,Win10 创作者版。结论是,Icon.ExtractAssociatedIcon() 不会从网络路径运行。它不会从 .ico 文件中读取图标,我的测试...

            Icon myImage;
            string fn = sIconPath + "\\" + cSymbolIconFile;
            try
            {
                if (File.Exists(fn)) myImage = Icon.ExtractAssociatedIcon(fn); 
                  else MessageBox.Show("Error: File not found.");
            } catch(Exception EE) { MessageBox.Show("Error: "+EE.Message); }
    

    当我的 sIconPath 是网络路径时,我得到一个异常提示 "Error: Value of is not valid for 'filePath'"

    现在要解决这个问题,您应该将图标文件放在资源中并将其包含在您的链接中。

    1. 在名为“mydll”的项目中创建资源,例如“buttonresources”,把你的图标文件放进去..

    2. 将 mydll.dll 放入可执行主项目的引用中

    3. 现在您的项目中应该有一个 buttonresources.resx。解决一个名为 e.g. 的图标“myicon”如下..

          System.Reflection.Assembly a1 = GetType().Assembly;
          var m = new System.Resources.ResourceManager("mydll.buttonresources", a1);
          Icon myImage = (System.Drawing.Icon)m.GetObject("myicon");
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      相关资源
      最近更新 更多