【发布时间】:2015-07-14 10:22:42
【问题描述】:
我正在尝试使用 Shell32 在 c# 中获取扩展文件属性。
我的代码如下。
var file = FileUpload1.PostedFile;
List<string> arrHeaders = new List<string>();
Shell shell = new ShellClass();
//Exception is thrown at next line
Folder rFolder = shell.NameSpace(Path.GetDirectoryName(file.FileName));
FolderItem rFiles = rFolder.ParseName(Path.GetFileName(file.FileName));
for (int i = 0; i < short.MaxValue; i++)
{
string value = rFolder.GetDetailsOf(rFiles, i).Trim();
arrHeaders.Add(value);
}
我得到如下异常。
消息 - 无法将“Shell32.ShellClass”类型的 COM 对象转换为接口类型“Shell32.IShellDispatch6”。此操作失败,因为 IID 为“{286E6F1B-7113-4355-9562-96B7E9D64C54}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)) .
堆栈跟踪 - 在 System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease) 在 Shell32.ShellClass.NameSpace(Object vDir) 在 c:\Projects\PBSWebApplication\PBSWebApplication\PBSWebApplication\Test.aspx.cs:line 33 中的 PBSWebApplication.Test.Button1_OnClick(Object sender, EventArgs e) 在 System.Web.UI.WebControls.Button.OnClick(EventArgs e) 在 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument) 在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,字符串 eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
如何解决这个问题?
谢谢。
【问题讨论】: