none
ErrorCode=-2146823114

    Question

  •   

    I am using VC# 2010 to open a Word 2007/2010 document stored in my system running on windows 7 platform, the code I am using is given below:

                    ApplicationClass wordApp = new ApplicationClass();

                    Paths = Paths + "\\" + strDayofWeek;

                    object file = Paths;

                    object nullobj = System.Reflection.Missing.Value;

                    * Document doc = wordApp.Documents.Open(

                                    ref file, ref nullobj, ref nullobj,

                                    ref nullobj, ref nullobj, ref nullobj,

                                    ref nullobj, ref nullobj, ref nullobj,

                                    ref nullobj, ref nullobj, ref nullobj,

                                    ref nullobj, ref nullobj, ref nullobj,

                                    ref nullobj);

    The line of code with asterisks  (*), generates the following error message:

    System.Runtime.InteropServices.COMException was unhandled

      HelpLink=C:\Program Files\Microsoft Office\Office12\1033\WDMAIN11.CHM#24654

      Message=This file could not be found.

     (C:\Users\...\Weekdays\Monday)

      Source=Microsoft Word

      ErrorCode=-2146823114

      StackTrace:

           at Microsoft.Office.Interop.Word.Documents.Open(Object& FileName, Object& ConfirmConversions, Object& ReadOnly, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Format, Object& Encoding, Object& Visible, Object& OpenAndRepair, Object& DocumentDirection, Object& NoEncodingDialog, Object& XMLTransform)

           at ARM.frmReadings.WriteFiles() in C:\Users\....\Readings.cs:line 917

           at ARM.frmReadings.OpenDayTypeFolda(String strWeekFolda) in C:\Users\...\Readings.cs:line 373

           at ARM.frmReadings.OpenWeekFolder(String strSeasonFolda) in C:\Users\...\Readings.cs:line 221

           at ARM.frmReadings.OpenSeasonFolder(String strPropersFolda) in C:\Users\...\Readings.cs:line 132

           at ARM.frmReadings.OpenPropersFolder() in C:\Users\...\Readings.cs:line 102

           at ARM.frmReadings.btnWrite_Click(Object sender, EventArgs e) in C:\Users\...\Readings.cs:line 88

           at System.Windows.Forms.Control.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnClick(EventArgs e)

           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

           at System.Windows.Forms.Control.WndProc(Message& m)

           at System.Windows.Forms.ButtonBase.WndProc(Message& m)

           at System.Windows.Forms.Button.WndProc(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

           at System.Windows.Forms.Application.Run(Form mainForm)

           at ARM.Program.Main() in C:\Users\...\Program.cs:line 20

           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           at System.Threading.ThreadHelper.ThreadStart()

      InnerException:

    How do I resolve it?

    • Moved by David Wolters Wednesday, March 14, 2012 3:16 PM moving to a more appropriate forum (From:Office IT Pro General Discussions)
    Wednesday, March 14, 2012 8:59 AM

Answers

  • I was seeing very similar problem. I was needing to inject a wait between starting Word up and then attempting to open the document.

    So... I just tried making sure I have the fully qualified path to the document that I am trying to open. When I did this all started working OK for me.

    So to be clear all I did was move from code that looked like this

    string filename = @"myDoc.docx");
    var document = wordApp.Documents.Open(FileName: filename, ReadOnly: true);

    over to something like

    string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , @"myDoc.docx");
    var document = wordApp.Documents.Open(FileName: filename, ReadOnly: true);

    Hope this helps.




    Friday, March 16, 2012 12:43 PM

All replies

  • Hi Adiposa,

    Thanks for posting in the MSDN Forum.

    What about variable "strDayofWeek" ? It's seems have error in it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 16, 2012 6:34 AM
    Moderator
  • Sorry, but strDayofWeek has no error on it, it has been declared earlier in the method and is used to read the days of the week from an array of days of the week.

    Thanks.

    Friday, March 16, 2012 7:37 AM
  • write before calling Open on Word app following line:

    MessageBox.Show(System.IO.File.Exists(file).ToString());

    what does it show?

    Friday, March 16, 2012 8:37 AM
  • I was seeing very similar problem. I was needing to inject a wait between starting Word up and then attempting to open the document.

    So... I just tried making sure I have the fully qualified path to the document that I am trying to open. When I did this all started working OK for me.

    So to be clear all I did was move from code that looked like this

    string filename = @"myDoc.docx");
    var document = wordApp.Documents.Open(FileName: filename, ReadOnly: true);

    over to something like

    string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , @"myDoc.docx");
    var document = wordApp.Documents.Open(FileName: filename, ReadOnly: true);

    Hope this helps.




    Friday, March 16, 2012 12:43 PM
  • Hi Adiposa,

    Do you try thesnark's work round?

    @thesnark,

    Thanks for sharing your experience here.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 19, 2012 6:08 AM
    Moderator