ACAT.Extensions.Default.FunctionalAgents.NewFile.NewFileAgent.createAndLaunchWordDoc C# (CSharp) Метод

createAndLaunchWordDoc() приватный Метод

Creates a word doc and launches word
private createAndLaunchWordDoc ( String fileName ) : bool
fileName String name of the file to create
Результат bool
        private bool createAndLaunchWordDoc(String fileName)
        {
            bool retVal = true;
            bool comCreated = false;
            Microsoft.Office.Interop.Word.Application wordApp = null;
            try
            {
                try
                {
                    wordApp = (Microsoft.Office.Interop.Word.Application)Marshal.GetActiveObject("Word.Application");
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    wordApp = null;
                }

                if (wordApp == null)
                {
                    wordApp = new Microsoft.Office.Interop.Word.Application();
                }
                else
                {
                    comCreated = true;
                }

                Microsoft.Office.Interop.Word.Document adoc = wordApp.Documents.Add();
                object missing = System.Reflection.Missing.Value;
                object f = fileName;
                adoc.SaveAs(
                        ref f,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing,
                        ref missing);

                adoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges, ref missing, ref missing);
                if (comCreated)
                {
                    Marshal.ReleaseComObject(wordApp);
                }

                wordApp = null;
                Process.Start(fileName);
                waitForWordWindow(fileName);
            }
            catch (Exception ex)
            {
                Log.Debug(ex.ToString());
                retVal = false;
            }
            finally
            {
                if (wordApp != null)
                {
                    Marshal.FinalReleaseComObject(wordApp);
                }
            }

            return retVal;
        }