我继承了一个基于Windows 2008 R2框的项目,它引用了Shell32.dll。
我需要这个项目在Windows 2003机器上工作,而且看起来Shell32.dll不包含" Target"在W2003盒子上的方法。
是否有相同的方法或方法?
这是代码:
serverlink = (ShellLinkObject)serverlinkfile.GetLink;
string spath = serverlink.Target.Path;
这是VS2010给我的错误:
' Shell32.ShellLinkObject'不包含'目标'的定义没有扩展方法'目标'接受类型' Shell32.ShellLinkObject'的第一个争论。可以找到(你错过了使用指令或程序集引用吗?)
更新 - 新错误:
对象引用未设置为对象的实例
OFFENDING CODE(Shell32.FolderItems items = sourceFolder.Items();)
FileSystemObject fso = new FileSystemObject();
if (!fso.FolderExists(destPath))
{
fso.CreateFolder(destPath);
}
ShellClass sc = new ShellClass();
Shell32.Folder sourceFolder = sc.NameSpace(sourcePath);
Shell32.Folder destFolder = sc.NameSpace(destPath);
Shell32.FolderItems items = sourceFolder.Items();
答案 0 :(得分:3)
ShellLinkObject的目标不是a documented property。否则有可能试图在10年的操作系统上运行代码。
请改用Path property。 Afaik它必须是物理路径,而不是虚拟shell文件夹。
答案 1 :(得分:0)
通常在使用COM并更改构建平台时,如果环境设置不正确,您可以获得类似的错误。
删除COM引用并重新添加它有时可以解决问题。