Professional InfoPath 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Professional InfoPath 2003 [Electronic resources] - نسخه متنی

Ian Williams, Pierre Greborio

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید











Integrating with Applications and Services

Previously, you have seen how to integrate with databases, Web services, and file systems. There are scenarios where you have to integrate with applications, such as Microsoft Word, Excel, and Outlook, and services such as MSMQ and IIS. In most of these cases you have to develop some script procedure in order to send data to back-end systems.

In the following section you see how to send an e-mail with an InfoPath document attached to it and how to write into a Microsoft Word document. The last sample integrates InfoPath with the MSMQ (Microsoft Message Queuing) service. As you will see, the samples demonstrate the power of InfoPath when you develop custom scripts in order to interact directly with applications.


Sending the Form by E-mail


When you need to integrate with Microsoft Office 2003, it is easier than with custom applications, since you already have a high level of integration. For example, you can send the document as an attachment to an e-mail in Microsoft Outlook 2003. If you don’t have Outlook 2003 available, but a previous version, you should use the CDO (Collaboration Data Objects) model:


function XDocument::OnSubmitRequest(eventObj)
{
try
{
XDocument.SaveAs("D:\Temp\document.xml");

var conf = new ActiveXObject("CDO.Configuration");
conf.Fields.Item("cdoSendUsingMethod") = 1; // cdoSendUsingPickup;
conf.Fields.Item("cdoSMTPServerName") = "somehost";
conf.Fields.Item("cdoSMTPConnectionTimeout") = 10; // quick timeout
conf.Fields.Item("cdoSMTPAuthenticate") = 1; //cdoAnonymous;
conf.Fields.Item("cdoURLGetLatestVersion") = true;
conf.Fields.Update();

var cdo = new ActiveXObject("CDO.Message");
cdo.To = "to@infopath.com";
cdo.From = "from@infopath.com";
cdo.Subject = "InfoPath document";
cdo.TextBody = "This is the document you are looking for.";
cdo.AddAttachment("D:\Temp\document.xml");

cdo.Send();

eventObj.ReturnStatus = true;
}
catch(e)
{
XDocument.UI.Alert(e.description);
eventObj.ReturnStatus = false;
}
}

First, you save the document on the file system. Then you configure the CDO with all parameters needed to send an e-mail (SMTP server, username, password, etc.). Next, you create the message, attaching the document saved. Finally, you send the message. You can delete the file after sending it to keep the local file system clean. The only problem you have is that the form must be fully trusted, since you are using the SaveAs function, which requires higher security privileges.


Updating a Microsoft Word Document


Consider a form where you collect contacts. You need a button in the form that updates a Microsoft Word document. You can create a script code that loads the Word application, fills the document content, saves the document, and closes the application.

This can be done with the Microsoft Word object model as shown in the following sample code:


function XDocument::OnSubmitRequest(eventObj)
{
try
{
var name = XDocument.DOM.selectSingleNode("//my:Name").nodeTypedValue;

var word = new ActiveXObject("Word.Application");
word.Visible = false;
word.Documents.Add();

var range = word.ActiveDocument.Range(0);
range.InsertAfter("Hello " + name);

word.ActiveDocument.SaveAs("D:\\Temp\\MyDocument.doc");
word.ActiveDocument.Close();

word.Quit();
word = null;

eventObj.ReturnStatus = true;
}
catch(e)
{
XDocument.UI.Alert(e.description);
eventObj.ReturnStatus = false;
}
}

You have to create a Word application object and then a new document. In the preceding sample, we are getting all defaults from Microsoft Word (normal document), but you can also define all the properties you want, such as the document template to use (.dot). When the document is created, you add the text. As you can see, the text is composed of two parts: one constant value (Hello) and one field content from InfoPath (Name). Finally, you save the document to the file system and close the Word application.


Sending a Document to MSMQ


The previous code listings are samples of integration with applications. You might also need to integrate with operating system services like MSMQ. In the following sample, you send the XML document into a queue of MSMQ:


function XDocument::OnSubmitRequest(eventObj)
{
try
{
var strFormatName = "DIRECT=OS:pew-wks1\\private$\\InfoPathQueue";

var qinfo = new ActiveXObject("MSMQ.MSMQQueueInfo");
qinfo.FormatName = strFormatName;
var qdest = qinfo.Open(2, 0);

var msg = new ActiveXObject("MSMQ.MSMQMessage");
msg.Label = "InfoPath document";
msg.Body = XDocument.DOM.xml;

msg.Send(qdest);

qdest.Close();

eventObj.ReturnStatus = true;
}
catch(e)
{
XDocument.UI.Alert(e.description);
eventObj.ReturnStatus = false;
}
}

The first parameter is the direct format name of the queue that tells the queue where to send the message. Then you open the queue and create the message with a constant label and the XML document as body. Finally, you send the message to the queue. Note that you can also define a message label depending on some fields content, concatenating the strings.

/ 166