How to open to develop a C Sharp Word Add In that acts the same as File>Open
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to open to develop a C Sharp Word Add In that acts the same as File>Open

  1. #1
    Join Date
    Nov 2011
    Posts
    38

    How to open to develop a C Sharp Word Add In that acts the same as File>Open

    I am developing a C Sharp Word AddIn that acts the same as the File>Open option. The exception is that when I click on the AddIn, I want it to ask the user which file they want to open...

    I have .NET Framework 4, Visual Studio 2010 and Word 2010.

    Here is the code so far...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Word = Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Word;
    using System.IO;


    namespace WordAddIn2
    {
    public partial class ThisAddIn
    {
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
    System.Console.Write("Enter the file name: ");
    String fileName = System.Console.ReadLine();

    Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
    Word._Document oDoc;
    oDoc = oWord.Documents.Open(@"H:\SNH\" + fileName);
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
    this.Startup += new System.EventHandler(ThisAddIn_Startup);
    this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
    }
    }


    When I add the AddIn to Word and try to run it, it produces an error saying "This file could not be found." However, it was supposed to ask the user which file to open and never did.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: How to open to develop a C Sharp Word Add In that acts the same as File>Open

    You are going to have to create a Windows.Form (or use WPF) and present it to the user. Currently you are using the console and that won't work.

  3. #3
    Join Date
    Mar 2013
    Posts
    1

    Re: How to open to develop a C Sharp Word Add In that acts the same as File>Open

    mu moi, mu moi ra, mu moi open, mu moi open hom nay, mu sap open mu moi, mu moi ra, murongbay.net,mu moi open, mu moi open hom nay, mu sap open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center