none
how to open word 2007 (docx) file RRS feed

  • Question

  • hi there

    I struggle to open normal docx word 2007 file 

    can i use open xml sdk to do that ?

    i actually generating a report from docx word file by updating the costume xml parts .

    using this code 

    -----------------


     public static void UpdateCustomXML()
        {
          string templatePath = "report.docx";
          string custXMLFilePath = "Data.xml";
    
          using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(templatePath, true))
          {
            MainDocumentPart mainPart = wdDoc.MainDocumentPart;
    
            // load custom XML
            XmlDataDocument custXML = new XmlDataDocument();
            custXML.Load(custXMLFilePath);
    
            // get the XML part that needs to be updated
            CustomXmlPart custXMLPart = mainPart.CustomXmlParts.ElementAtOrDefault(0);
    
            // update the content of the custom XML part
            using (Stream myStream = custXMLPart.GetStream(FileMode.Create))
            {
              custXML.Save(myStream);
            }
          }
        }
    
    

    ----------------

    and every thing works fine and data saved to the word file

     i just need to open the word file .

     

    i try this code but nothing happen 

     object missing = System.Reflection.Missing.Value;
          object True = true;
          object Talse = false;
          
          //Creating objects of word and document
          Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
    
          Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
    
          //Adding a new document to the application
          oWordDoc = oWord.Documents.Add(ref missing, ref missing, ref missing, ref missing);
    
          // To open an existing word document we need to pass the path of the existing document with some // other parameters. Here is the code snippet opening an existing word document
    
          object fileName = "c:\\yahoo.docx";
          // You can keep it true if you want to open the file in readonly mode
          object readOnly = false;
          // we can keep it false if you want to open the file but not make it invisible
          object isVisible = true;
    
          oWordDoc = oWord.Documents.Open(ref fileName, ref missing, ref 
             readOnly, ref missing, ref missing, ref missing, ref 
             missing, ref missing, ref missing, ref missing, ref
             missing, ref isVisible, ref missing, ref missing, ref
             missing, ref missing);
    

    any help ?

    Tuesday, March 15, 2011 9:27 PM

Answers

  • Done

     string path = System.Windows.Forms.Application.StartupPath + "\\" + "report.docx";

     System.Diagnostics.Process.Start(path);

    • Marked as answer by Bruce Song Thursday, March 17, 2011 2:39 AM
    Tuesday, March 15, 2011 10:45 PM

All replies

  • Done

     string path = System.Windows.Forms.Application.StartupPath + "\\" + "report.docx";

     System.Diagnostics.Process.Start(path);

    • Marked as answer by Bruce Song Thursday, March 17, 2011 2:39 AM
    Tuesday, March 15, 2011 10:45 PM
  • Hi Omar,

    It seems that you have resolved your problem. Thank you for sharing your solution and this may do help to other community members who have similar problems.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 17, 2011 2:38 AM