open a word file with a button?

M

Matt

Hi Folks,
I am trying to open a particular word file at the press of a button in a
form in InfoPath. Does anyone know a way to do this? Thanks!
Matt
 
G

G. Tarazi

You must have the Microsoft Office 2003 SDK for VS.NET 2003 (the one
available for MSDN subscribers only)

using Office = Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;


object missing = Type.Missing;
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;

// Open word
Word.ApplicationClass wApp = new Word.ApplicationClass();
object objPaFileName = "the file path here";

// Open Document
Word.Document document = wApp.Documents.Open(ref objPaFileName, 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);

// Close word
document.Close(ref doNotSaveChanges, ref missing, ref missing);
wApp.Quit(ref doNotSaveChanges, ref missing, ref missing);

To show word, change the property of visible to true
 
B

Brian Teutsch [MSFT]

You can also use JScript or VBScript with custom code behind your button.
Your form must be fully trusted to use either Script or Managed Code.

var wdApp; // a general variable
try {
wdApp = new ActiveXObject("Word.Application");
wdApp.Visible = true;
wdApp.WindowState = 1;
var docObj = null;
docObj = wdApp.Documents.Open(wordDocumentPath);
// wdApp.Quit();
}
catch (e) {
wdApp.Quit();
XDocument.UI.Alert("Printing the Word document failed.");
}

Brian
 
M

Matt

how do I know if my form is fully trusted? I don't see anything enabling that
under the options. Thanks!
Matt
 
B

Brian Teutsch [MSFT]

Check the archives of this group for a wealth of information on making your
form fully trusted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top