MrM
MrM

Reputation: 21989

How do I reference a word document in my project

I would like to use a word file in my visual studio project for edits and return the file.

Microsoft.Office.Interop.Word.Document tempDoc = null;
try
{
    object missing = System.Reflection.Missing.Value;
    Application wordApp = new Application();

    //I have a copy on C: and this works.
    object useFileName = "C:\\WordFile.doc";

    object readOnly = false;
    object isVisible = false;
    wordApp.Visible = false;
    tempDoc = wordApp.Documents.Open(ref useFileName, ref missing,
        ref missing, 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);
    ...
    }
    return tempDoc;

How do I reference the word document in my project (Content/Documents/WordFile)?

Upvotes: 0

Views: 1121

Answers (2)

Paul J
Paul J

Reputation: 476

You can get the location on the executing code from System.Reflection.Assembly.GetExecutingAssembly().Location;

Alternatively place the document location in the config file.

Upvotes: 1

Jorge
Jorge

Reputation: 18237

Maybe using Server.MapPath which specifies the relative or virtual path to map to a physical directory.

Server.MapPath("~/Content/Documents/WordFile")

Upvotes: 1

Related Questions