Click here to Skip to main content
16,011,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
        }
    }
}


regards
kumaran
Posted
Updated 10-Apr-10 2:07am
v2

1 solution

Not your code is it.

And whats the point of doing a half assed job of conversion - with no notification.

There is a way - but you are going to have to improve your logic AND google skills.

Sorry, but this is all so wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900