本文介绍了如何抑制文本转换自动过程中显示的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我将所有文档自动转换为驻留在文件夹中的文本文件.
有些文档受到密码保护.
因此,当我打开文档时,它会显示警告,如下图所示.
它会中断自动转换并要求手动干预
我需要抑制那些警报显示.或者我希望那些受密码保护的文档被跳过
可以帮助我克服这个问题
这是我的代码
Hi
I am automate the convertion all my documents into text file which resides in a folder.
some of the document are been password protected.
so while i am opening the document it show an alert as shown in attached image.
it interupts the automated conversion and ask for manual intervention
i need to supress those alerts display. or i want those document which are password protected to be skipped
can help me to overcome the issue
here is my code
private void TextFileConvertion(string strsource, string strtarget)
{
// Use for the parameter whose type are not known or
// say Missing
object Unknown = Type.Missing;
//Creating the instance of Word Application
Word.Application newApp = new Word.Application();
Word.Document doc = null;
newApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
try
{
lblProgress.Text = "Converting " + strsource + " into Text file is under process.";
Application.DoEvents();
// specifying the Source & Target file names
object Source = strsource;
object Target = strtarget;
// Source document open here
// Additional Parameters are not known so that are
// set as a missing type
doc = newApp.Documents.Open(ref Source, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
if (doc.ReadOnlyRecommended == true)
return;
// Specifying the format in which you want the output file
object format = Word.WdSaveFormat.wdFormatText;
//Changing the format of the document
newApp.ActiveDocument.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
//if (doc.ReadOnlyRecommended == true)
// SetuncheckReadonly(doc, strsource);
//intTxtCounter = intTxtCounter + 1;
strTxtCounter = "OK";
}
catch (Exception ex)
{
strTxtCounter = "FAILED";
ZoniacLogger.Error(" Exception : " + ex.Message + " Stack Trace : " + ex.StackTrace);
}
finally
{
if (newApp != null)
{
// for closing the application
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
newApp = null;
}
}
}
问候
kumaran
regards
kumaran
推荐答案
这篇关于如何抑制文本转换自动过程中显示的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!