Sto tentando di utilizzare Shell32 per ottenere proprietà di file estese in C#.Eccezione quando si utilizza Shell32 per ottenere proprietà estese di file
Il mio codice per questo è il seguente.
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);
}
Ottengo eccezione come segue.
Messaggio: impossibile eseguire il cast dell'oggetto COM di tipo "Shell32.ShellClass" sul tipo di interfaccia "Shell32.IShellDispatch6". Questa operazione non è riuscita perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' non è riuscita a causa del seguente errore: Nessuna interfaccia supportata (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)) .
Stack Trace - a System.StubHelpers.StubHelpers.GetCOMIPFromRCW (Object objSrc, IntPtr pCPCMD, IntPtr & ppTarget, booleano & pfNeedsRelease) a Shell32.ShellClass.NameSpace (Object vdir) a PBSWebApplication.Test.Button1_OnClick (Object mittente, EventArgs e) in c: \ Projects \ PBSWebApplication \ PBSWebApplication \ PBSWebApplication \ Test.aspx.cs: riga 33 su System.Web.UI.WebControls.Button.OnClick (EventArgs e) su System.Web.UI. WebControls.Button.RaisePostBackEvent (String eventArgument) su System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (String eventArgument) su System.Web.UI.Page.RaisePostBa ckEvent (IPostBackEventHandler SourceControl, String eventArgument) a System.Web.UI.Page.RaisePostBackEvent (NameValueCollection postData) a System.Web.UI.Page.ProcessRequestMain (booleano includeStagesBeforeAsyncPoint, booleano includeStagesAfterAsyncPoint)
Come risolvere questo problema?
Grazie.
ciò che è buono cattura e buona soluzione anche! –