戰地連結︰ Home My Flickr NBA.com About

顯示包含「InfoPath 2007」標籤的文章。顯示所有文章
顯示包含「InfoPath 2007」標籤的文章。顯示所有文章

2008年6月26日星期四

My struggle with Browser enabled InfoPath Form connection to 'UserProfileService' Web Service

Overview

I faced a silly error when trying to use data connection in a Browser-enabled InfoPath Form to connect to MOSS built-in 'UserProfileService' web service in order to retrieve the display name (Preferred Name) of the logged in user. It works great without any error when I preview the form in InfoPath. However, I keep seeing the "ID 5566" error after I published the form to a document library and open it in browser. On the other hand, the published form works to show the current logged in user of the computer (not the MOSS portal) when opened in a client application (i.e. InfoPath).

Symptom

  1. Fail with "ID 5566" error when the form is opened in web browser.
  2. Work without error when opened in preview mode or in client application, shows the logged in user of the computer.
  3. Fail to work with all methods in 'UserProfileService' web service.

Cause

After many googling and trial & error, I still can't find the cause. Or I actually overlooked one suggestion in a post. That is the "Allow Anonymous login" option. I thought that this is the option in "Central Administration" -> "Application Management" -> "Authentication Providers" -> "Edit Authentication". But actually the main problem is at IIS settings of the web applications' authentication.

Reference

InfoPath - Get the current user without writing code

Steps to disable "anonymous login" in "IIS Manager"

  1. In Windows Server 2003 R2, click "Start" -> "Administrative Tools" -> "Internet Information Services (IIS) Manger"
  2. In "IIS Manager", expand the name of your computer on the left pane, expand "Web Sites"
  3. Right click on the web application you want to edit (e.g. mine is "SharePoint - 80", select "Properties"
  4. In "Properties", select "Directory Security" tab. Press "Edit" in the "Authentication and access control" category
  5. Uncheck "Enable anonymous access" in "Authentication Methods", click "OK" to go back to IIS Manager

2008年5月20日星期二

Working with InfoPath Repeatable Table/Section in MOSS workflows

Overview

With an InfoPath form as a workflow list item, we can gain access to its data via workflowProperties.Item. However, there is no native support in MOSS workflows for repeating table/sections. So we developers have to write custom helper method to gain this function.

Reference

Julie's Office Dev Blog : InfoPath 2007, SharePoint Workflows and Whatnot

Code Snippet

Parse repeating data in an InfoPath form (normally this is the submit form)
This code is copied form "MOSS SDK Workflow Example - Inter-System Purchase Order" by Microsoft

    1 private void GetLineItemsFromOrder(out DateTime dueDate, out LineItem[] items)

    2 {

    3     List<LineItem> LineItems = new List<LineItem>();

    4 

    5     //Load the bytes for the document

    6     byte[] xmlBytes = this.workflowProperties.Item.File.OpenBinary();

    7 

    8     //Remove the BOM from the xml file so XmlDocument Can handle it

    9     string Xml = System.Text.Encoding.UTF8.GetString(xmlBytes);//, 1, xmlBytes.Length - 1);

   10     if (Xml[0] == (char)0xfeff)

   11     {

   12         Xml = Xml.Substring(1);

   13     }

   14 

   15     XmlDocument Document = new XmlDocument();

   16     Document.LoadXml(Xml);

   17 

   18     XmlElement RootElement = Document.DocumentElement;

   19 

   20     XmlNamespaceManager Manager = new XmlNamespaceManager(Document.NameTable);

   21     Manager.AddNamespace("my", RootElement.NamespaceURI);

   22 

   23     //Get Due Date

   24     dueDate = DateTime.Parse(RootElement.SelectSingleNode("//my:ShipBy", Manager).InnerText);

   25 

   26     //Get Order Details

   27     XmlNodeList OrderItems = RootElement.SelectNodes("//my:OrderItem", Manager);

   28     foreach(XmlNode OrderItem in OrderItems)

   29     {

   30         LineItem LineItem = new LineItem();

   31         LineItem.ProductID = OrderItem.SelectSingleNode("my:ProductID", Manager).InnerText;

   32         LineItem.Quantity = OrderItem.SelectSingleNode("my:Quantity", Manager).InnerText;

   33         LineItems.Add(LineItem);

   34     }

   35 

   36     items = LineItems.ToArray();

   37 

   38 }

Passing repeating data to an InfoPath task form
In MOSS workflows, InfoPath task form is receiving data by setting up a secondary data source bound to a "ItemMetadata.xml" file. Unfortunately, repeating data schema is not supported in this file.

In this example, I will try to send the data in original list item file to the InfoPath task form, I am sending over the actual xml of the original list item file as a string value in the ItemMetadata. To get the actual xml of the original list item file, we can use the code snippet extracted from above example:

//Load the bytes for the document

byte[] xmlBytes = this.workflowProperties.Item.File.OpenBinary();

 

//Remove the BOM from the xml file so XmlDocument Can handle it

string Xml = System.Text.Encoding.UTF8.GetString(xmlBytes);//, 1, xmlBytes.Length - 1);

if (Xml[0] == (char)0xfeff)

{

    Xml = Xml.Substring(1);

}

 

Here we get the string variable "Xml" as the xml of the original list item file, and we can pass it to ItemMetadata. Next step is to parse this xml string into repeating data in the InfoPath task form, to do this, we have to write custom code in the InfoPath task form, will require the form to be "Fully Trust". The code snippet of the task form is as below:

public void FormEvents_Loading(object sender, LoadingEventArgs e)

{

    string xmlSource = this.DataSources["ItemMetadata"].CreateNavigator().SelectSingleNode("/z:row/@ows_repeatData", NamespaceManager).Value;

 

    XmlDocument nodeDoc = new XmlDocument();

    nodeDoc.LoadXml(xmlSource);

    XPathNavigator sectionNode = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields", NamespaceManager);

    string ns = sectionNode.NamespaceURI;

 

    //we need to delete the default one Infopath adds in

    this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:repeatDetail", NamespaceManager).DeleteSelf();

 

    foreach (XmlNode thisNode in nodeDoc.DocumentElement.ChildNodes)

    {

        if ((thisNode.LocalName == "repeatDetail"))

        {

            //Start populating the data

            XmlWriter write = sectionNode.AppendChild();

            write.WriteStartElement("my", "repeatDetail", ns);

            write.WriteElementString("my", "DataColumn1", ns, "Value1");

            write.WriteElementString("my", "DataColumn2", ns, "Value2");

            write.WriteElementString("my", "DataColumn3", ns, "Value3");

            write.WriteElementString("my", "DataColumn4", ns, "Value4");

            write.WriteEndElement();

            write.Close();

        }

    }

}  

2008年5月15日星期四

Custom 'Save' Button in InfoPath Form to save into MOSS Document Library

Overview

I always try to hide the Top and Bottom Toolbar (the one showing "Save", "SaveAs", "Close") in my Browser-enabled InfoPath Forms. But how can I let the user to save the Form into a Document Library without showing the toolbar?. The answer is to submit the form to the destination MOSS Document Library.

Reference

Create a custom Save Button in InfoPath

Steps

  1. In InfoPath 2007, choose 'Tools' => 'Submit Options'
  2. Check 'Allow users to submit this form', choose 'Send form data to a single destination' radio button, select 'SharePoint document library' in the dropdown under the 'Send form...' radio button.
  3. Under the 'SharePoint document library' dropdown, click 'Add' button.
  4. In 'Data Connection Wizard', enter the full URL of the Document Library (e.g. "http://localhost/Doc Lib/Forms/AllItems.aspx" ) in the 'Document Library' Text box.
  5. Enter File name for the saved Form, you can add function to dynamically create file name. (By clicking the 'fx' button on the right). Click 'Next'
  6. Enter the name for this data connection.
  7. After you create the data connection, you should convert it into .udcx file and saved in inside the MOSS server for administrator approval. Check My Previous Post for detail steps.

2008年5月11日星期日

How to embed browser-enabled InfoPath Forms into Webpart

Overview

To have a browser-enabled InfoPath Form is nice, but to have an InfoPath Form embed webpart that can be put at anywhere in your page is even more nicer!!! The following PDF file by Nick Grattan Consultancy Limited will shows you how to used out-of-the-box "XmlFormView" Library as a webpart container of browser-enabled InfoPath Forms.

Reference

How to Host Microsoft InfoPath Forms in SharePoint 2007 Web Part Pages (PDF)

2008年5月2日星期五

MOSS hosted InfoPath Form with Web Services Data Connection

Overview

在上一篇文 Publish Browser Enabled InfoPath Form to MOSS 2007 中分享了製作 MOSS browser enabled InfoPath Form 的方法. 今次就再為InfoPath Form 加上 Web Services 既 Data Connection.

Reference

  1. InfoPath and Web Service data connection
  2. Data Connections in Browser Forms
  3. Data Connection Libraries
  4. Publish a form template to a server running InfoPath Forms Services
  5. How to: Deploy Form Templates That Contain Form Code
  6. MSDN - Visual Studio 2005 Tools for Applications

Steps

我的經驗告訴我, 所有與 SharePoint 扯上關係的 Development 都不會像表面所看那麼簡單... 一定有很多困難的地方. 這次都不例外, 看看上面列出的 reference link 數目之多就可知道...

在下面我只會例出簡單的流程, 並指出相對應的 reference.

  1. 當然是先要建立起一個web service吧. 這個用 Visual Studio 2005 可以輕鬆做到.
  2. 建立與web service溝通的 InfoPath Form Template. 在 InfoPath 2007 中的 "Design a Form Template" Wizard 可以讓你一步一步建立起以 web service 做為 data source 及 submit target 的 Form Template. 詳細請參考 Reference 1. 下面列出幾點要注意的地方︰
    2.1   在 "Design a Form Template" Wizard 中可以選 "Enable browser-compatible features
            only", 可以避免誤用與 browser 不相容的功能.
    2.2   在 "Tools" => "Form Options" => "Compatibility" 中選 "Design a form template that
            can ......"
    , 再將要 deploy / test 的 MOSS 的 URL 打入. InfoPath 就會用動替你找出
            template中任何與 server 不相容的地方, 並顯示在 "Design Checker" 中看到.
  3. 在 InfoPath 中, 將 Data Connection Convert 並存放在 MOSS 的 Data Connection Library 中, 等候 MOSS Administrator Approve (在 development 的時候, 應該你自己就是 administrator). 詳細請參考 Reference 3. 這步驟很重要, 不然之後在 browser submit form 的時候會出 Security Notice.
  4. 好~ InfoPath 的 Form Template 做完. 跟著就要去 MOSS 做 configuration. 先去 "Central Administration" Page, 再 "Application Management" => "Configure InfoPath Form Services", 然後選 "Allow cross-domain data access .....".
  5. 最後再去之前 Step 3 中 store Data Connection 的 MOSS Data Connection Library, 將所有要用的 Data Connection 都 Approve (當然要用 Administrator account Login). Step 4, 5 都請參考 Reference 2 & Reference 4.
  6. 最後將 Form Template Publish 去 MOSS, new 一張 Form 試一下, 如果沒問題就完成了!

Reference 5, 6 是關於如何在 InfoPath 中寫 custom code, 這將需要 VSTA. 而且 depoly 去 MOSS 的時候也有多些 configure 要做, 就不在這裡多講了.

2008年4月29日星期二

Publish Browser Enabled InfoPath Form to MOSS 2007

今日開始玩InfoPath, 想publish一張 InfoPath 既 form 入 SharePoint Server 做 WebPart, 但係0向 publish 既時候就見到呢個warning...

"This form template is browser-compatible, but it cannot be
browser-enabled on the selected site
"

結果搞左一大輪先搞得掂... 方法請參考下面既link

Reference:

A checklist for enabling browser forms with Forms Services and SharePoint 2007

KeyPoint:

其實我跟足 Reference 既方法都唔得, 原因大概係因為0向 SharePoint 做 setting 既時候 server未可以成功改到setting. 咁就可以根據以下keypoint試試︰

  1. 做完第 1, 2 步之後, 可以 restart 一次 IIS 先再做 step 3.
  2. 如果去到 "Site collection features" 搵唔到 "InfoPath Forms Services support", 就去 "Office SharePoint Server Enterprise Site Collection features"
  3. 如果所有步驟都無效, 就做以下動作, 手動 restart 個 feature︰
    3.1   去 SharePoint Server, 入 command prompt, 去 folder: "Program Files\Common
            Files\Microsoft Shared\web server extensions\12\BIN"

    3.2   輸入 "stsadm -o deactivatefeature -filename IPFSSiteFeatures\feature.xml -force -url
            http://YourMOSSurl"
    3.3   Operation Success 後, 再輸入 "stsadm -o activatefeature -filename
            IPFSSiteFeatures\feature.xml -force -url
    http://YourMOSSurl"