dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.28k stars 955 forks source link

In .NET code is going to exception section when we are trying to convert a sensitivity label doc file to docx format. Exception is Command failed #11501

Closed ASHISDEY1998 closed 3 weeks ago

ASHISDEY1998 commented 3 weeks ago

.NET version

8.0.104

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

Here is the code I am currently using

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); var sourceFile = new FileInfo(path); try { var document = wordApp.Documents.Open(sourceFile.FullName); string newFileName = Path.Combine(Path.GetDirectoryName(sourceFile.FullName), Path.GetFileNameWithoutExtension(sourceFile.FullName) + "_c.docx"); document.SaveAs2(newFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Microsoft.Office.Interop.Word.WdCompatibilityMode.wdCurrent);

document.Close();
GC.Collect();
wordApp.Quit();
Marshal.FinalReleaseComObject(wordApp);
return newFileName;

} catch (Exception ex) { errorLogger.LogException(ex); GC.Collect(); wordApp.Quit(); Marshal.FinalReleaseComObject(wordApp); return string.Empty; }

this code I am using to take a doc file and convert it to docx.

its working fine for normal file but when I try to use document with sensitivity label added in it its directly going to exception and giving me ex = {"Command failed"} error.

Steps to reproduce

Try to upload a doc file which is having sensitivity label its going to exception.

merriemcgaw commented 3 weeks ago

The Office products do not support automation with .NET 5+. You can continue to use .NET Framework for your Office automation needs however.