在 Microsoft Office InfoPath 2003 中,無法直接將表單資料送出至 Microsoft
Windows SharePoint Services 文件庫。本文說明如何設計使用指令碼的表單範本,將表單資料送出至 Windows SharePoint
Services 文件庫。
您可以在 InfoPath 2003 Service Pack 1 中藉由使用其 UI,將表單資料直接送出至
Windows SharePoint Services 文件庫。您必須使用本文包含的步驟來執行這項操作。
設計表單資料來源和版面配置
- 啟動 InfoPath 2003。設計新的空白表單。
- 在 [資料來源]
工作窗格中,新增表單的資料來源。如果要執行這項操作,請依照下列步驟執行:
- 用滑鼠右鍵按一下 [myFields],然後按一下
[新增]。
隨即顯示 [新增欄位或群組]
對話方塊。 - 輸入 FirstName 當做欄位的名稱,然後按一下
[確定]。
- 重複步驟 a。輸入 MiddleInitial
當做欄位名稱,然後按一下 [確定]。
- 重複步驟 a。輸入 LastName 當做欄位名稱,然後按一下
[確定]。
- 將 [myFields] 新增至表單。
- 按一下 [有控制項的區段]。
將表單資料送出至 SharePoint Services 文件庫
您可以使用指令碼或 UI 將表單資料送出至 SharePoint Services 文件庫。
在 InfoPath 2003 中使用指令碼將表單資料送出至 SharePoint Services 文件庫
- 按一下 [工具] 功能表上的
[送出表單]。
[送出表單] 對話方塊便會出現。 - 在 [送出表單] 對話方塊中,按一下
[允許送出]。
- 在 [送出] 方塊中,按一下
[使用自訂指令碼送出]。
- 按一下 [開啟 Microsoft Script Editor],再按一下
[確定]。
Microsoft Script Editor 隨即啟動。 - 依照下列方式修改 OnSubmitRequest 事件。
注意 您必須將程式碼中的 strURL 變數值變更為有效的 URL。下列程式碼範例中的 URL 會指向名為
ServerName 的伺服器、名為
SiteName 的 SharePoint 網站,以及名為
DocumentLibraryName 的文件庫。function XDocument::OnSubmitRequest(eventObj)
{
// If the submit operation is successful, set
// eventObj.ReturnStatus = true.
var fSuccessful = false;
// Set the URL of the file that you want to submit here.
var strUrl = "http://ServerName/SiteName/DocumentLibraryName/testform.xml";
try
{
// Create an xmlhttp object.
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
// See whether the document with the same name already exists in the Windows SharePoint Services (WSS) document library.
oXmlHttp.Open("HEAD", strUrl, false);
oXmlHttp.Send();
// No document with the URL has been found. Continue to submit.
// If you must replace the original file, you must call
// oXmlHttp.Open("DELETE", strUrl, false) to delete the document
// in the WSS document library.
if (oXmlHttp.Status == 404)
{
// Put the document in the WSS document library.
oXmlHttp.Open("PUT", strUrl, false);
oXmlHttp.Send(XDocument.DOM.xml);
// A 200 status code or a 201 status code indicates that the form has been submitted successfully.
if (oXmlHttp.Status == 200 || oXmlHttp.Status == 201)
{
fSuccessful = true;
}
}
}
catch (ex){}
if (fSuccessful)
{
XDocument.UI.Alert("Document submitted successfully.");
eventObj.ReturnStatus = true;
}
else
{
eventObj.ReturnStatus = false;
}
}
- 儲存指令碼。關閉 Script Editor。
- 將表單範本儲存為 SubmitToWSS.xsn。
在 InfoPath 2003 Service Pack 1 中使用 UI 將表單資料送出至 SharePoint Services 文件庫
- 按一下 [工具] 功能表上的
[送出表單]。
[送出表單] 對話方塊便會出現。 - 在 [送出表單] 對話方塊中,按一下
[啟用送出命令和按鈕]。
- 在 [送出至] 區段中,按一下 [SharePoint
表單庫]。
- 在 [送出表單] 對話方塊中,按一下
[新增]。
[資料連線精靈] 隨即啟動。 - 將 SharePoint Services 表單庫連結輸入 [SharePoint
表單庫]
方塊。
您的表單庫連結可能看來如下:
http://ServerName/SiteName/DocumentLibraryName - 在 [檔案名稱] 方塊中輸入文件名稱。
您可以使用
TestForm 之類的文件名稱。
按一下 [下一步]。 - 在資料連線精靈中, 按一下
[完成]。
- 在 [送出表單] 對話方塊中,按一下
[確定]。
- 將表單範本儲存為 SubmitToWSS.xsn。
測試表單
- 在 [檔案] 功能表上,按一下
[填寫表單]。
- 在 [填寫表單] 工作窗格中,按一下
[SubmitToWSS]。
- 完成表單。
- 在 [檔案] 功能表上按一下
[送出]。
如果成功送出表單,您便會收到指出表單已成功送出的訊息。 - 結束 InfoPath。如果系統提示您儲存對表單的變更,按一下
[否]。
- 啟動 Microsoft Internet
Explorer。找出文件表單庫。
例如,您的文件表單庫可能是
http://ServerName/SiteName/DocumentLibraryName。
文件庫中有名為
testform 的新項目。 - 按一下 [testform]。
您所送出的表單會在
InfoPath 2003 中開啟。
如需有關如何取得 Microsoft Office 最新版 Service Pack
的詳細資訊,請按一下下面的文件編號,檢視「Microsoft 知識庫」中的文件:
870924?
(http://support.microsoft.com/kb/870924/
)
如何取得 Office 2003 的最新版 Service Pack
如需有關如何在 InfoPath 2003
表單中使用指令碼的詳細資訊,請按一下下面的文件編號,檢視「Microsoft 知識庫」中的文件:
828853?
(http://support.microsoft.com/kb/828853/
)
How to: Change the Script Language for Your InfoPath Form
827002?
(http://support.microsoft.com/kb/827002/
)
How to debug a script for a Microsoft Office InfoPath 2003 Form