我正在使用以下代码将文件夹中的文档转换为 PDF
string[] filePaths = Directory.GetFiles(txtFolderPath.Text, "*.doc",
SearchOption.TopDirectoryOnly);
foreach (string path in filePaths)
{
Application app = new Application();
app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
app.Visible = true;
var objPresSet = app.Documents;
var objPres = objPresSet.Open(path, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
var temppath = path;
var pdfFileName = Path.ChangeExtension(path, ".pdf");
var pdfPath = Path.Combine(Path.GetDirectoryName(path), pdfFileName);
try
{
objPres.ExportAsFixedFormat(
pdfPath,
WdExportFormat.wdExportFormatPDF,
false,
WdExportOptimizeFor.wdExportOptimizeForPrint,
WdExportRange.wdExportAllDocument
);
}
catch
{
pdfPath = null;
}
finally
{
objPres.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
}
但是对于每个文档,即使我已将警报设置为无,我也会在下面弹出。
由于文件数量巨大,如何在 C# 中以编程方式停止此警报。