ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Saturday, May 19, 2012

Populating InfoPath Drop Down List Box with SharePoint Fields Choice

Populate InfoPath drop-down programmatically from Sharepoint Field Choice

  • Article 1: How to code C-Sharp on infopath form 2010
  • Article 2: How to set the value of a Field in Infopath
  • Article 3: How to set value of a field from sharepoint list
  • Article 4: Populating InfoPath Drop Down List Box with SharePoint List Lookup Data 
  • Article 5Populating InfoPath Drop Down List Box with SharePoint Fields Choice
  • Article 6: Deploy an InfoPath 2010 Form with Managed Code to a Browser Enabled Sharepoint Document Library

Download Infopath Form at here

Designing  and coding infopath

Open Infopath | Design user interface follows as

Go to File => Form Options => Programming
Form template code language: C#
Go to File => Form Options => Security and Trust
Configure follows as:
Go to Tab Developer | click to Loading Event ribbon
Right click to myFields | Add
Name: GroupStatus
Type: Group
Check to Repeating
Right click to GroupStatus | Add
Name: Displayname
Continue Right click to GroupStatus | Add then input Name: Value
Right click to DropdownList “Country” | Drop-Down List Box Properties…
At List box choices------------------------------
Check to radio button “Get choice from fields in this from”, then click to Entries, select value follows as
Add reference to Microsoft.sharepoint.dll
Using  using Microsoft.SharePoint;
Add method AddStatus (); to FormEvents_Loading
Paste this method  to below FormEvents_Loading method public void AddStatus ()
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;

namespace SetValueToDropdownListInfoPathFromChoiceField
{
    public partial class FormCode
    {
        // NOTE: The following procedure is required by Microsoft InfoPath.
        // It can be modified using Microsoft InfoPath.
        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
        }

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            AddStatus();
        }

        public void AddStatus()
        {
            try
            {
                SPSite site = new SPSite("http://win-67038mbkel7");
                SPWeb web = site.OpenWeb();
                SPList list = web.Lists["Tasks"];
                SPFieldMultiChoice spFieldMultiChoice = (SPFieldMultiChoice)list.Fields["Status"];
                XPathNavigator nav = this.CreateNavigator().SelectSingleNode("/my:myFields/my:GroupStatus",
                    this.NamespaceManager);
                for (int item = 0; item < spFieldMultiChoice.Choices.Count; item++)
                {
                    XPathNavigator newNode = null;
                    newNode = nav.Clone();
                    newNode.SelectSingleNode("/my:myFields/my:GroupStatus/my:Displayname",
                        this.NamespaceManager).
                        SetValue(spFieldMultiChoice.Choices[item].ToString());
                    newNode.SelectSingleNode("/my:myFields/my:GroupStatus/my:Value",
                        this.NamespaceManager).
                        SetValue(spFieldMultiChoice.Choices[item].ToString());
                    nav.InsertAfter(newNode);
                    newNode = null;
                }
                nav.DeleteSelf();
                nav = null;
            }
            catch
            {

            }
        }
    }
}


Build project then click F5, result as below

Deploy an InfoPath 2010 Form with Managed Code to a Browser Enabled Sharepoint Document Library

Populating InfoPath Drop Down List Box with SharePoint List Lookup Data

Populate InfoPath drop-down programmatically from Sharepoint List Lookup data



  • Article 1: How to code C-Sharp on infopath form 2010
  • Article 2: How to set the value of a Field in Infopath
  • Article 3: How to set value of a field from sharepoint list
  • Article 4: Populating InfoPath Drop Down List Box with SharePoint List Lookup Data 
  • Article 5Populating InfoPath Drop Down List Box with SharePoint Fields Choice
  • Article 6: Deploy an InfoPath 2010 Form with Managed Code to a Browser Enabled Sharepoint Document Library

Download infopath project at here

Designing  and coding infopath

Open Infopath | Design user interface follows as
Go to File => Form Options => Programming
Form template code language: C#
Go to File => Form Options => Security and Trust
Configure follows as:
Go to Tab Developer | click to Loading Event ribbon
Right click to myFields | Add
Name: Countries
Type: Group
Check to Repeating
Right click to Countries | Add
Name: Displayname
Continue Right click to Countries | Add then input Name: Value
Right click to DropdownList “Country” | Drop-Down List Box Properties…
At List box choices------------------------------
Check to radio button “Get choice from fields in this from”, then click to Entries follows as
Select value follows as
Open your  site collection | Create new list Countries then add new some Item
Add reference to Microsoft.sharepoint.dll
Using  using Microsoft.SharePoint;
Add method AddCountries(); to FormEvents_Loading

Paste this method  to below FormEvents_Loading method public void AddCountries()
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;

namespace PopulateDropdownListFromCode
{
    public partial class FormCode
    {       
        // NOTE: The following procedure is required by Microsoft InfoPath.
        // It can be modified using Microsoft InfoPath.
        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
        }

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            //Populate country drop down
            AddCountries();
        }

        public void AddCountries()
        {
            try
            {
                SPSite site = new SPSite("http://win-67038mbkel7");
                SPWeb web = site.OpenWeb();
                SPList list = web.Lists["Countries"];
                SPListItemCollection listitems = list.Items;
                XPathNavigator nav = this.CreateNavigator().
                    SelectSingleNode("/my:myFields/my:Countries", this.NamespaceManager);// Note: "/my:myFields/my:Countries" => Group Countries
                foreach (SPListItem li in listitems)
                {
                    XPathNavigator newNode = null;
                    newNode = nav.Clone();
                    newNode.SelectSingleNode("/my:myFields/my:Countries/my:Displayname",
                        this.NamespaceManager).SetValue(li["Title"].ToString());
                    newNode.SelectSingleNode("/my:myFields/my:Countries/my:Value",
                        this.NamespaceManager).SetValue(li["Title"].ToString());
                    nav.InsertAfter(newNode);
                    newNode = null;
                }
                nav.DeleteSelf();
                nav = null;
            }
            catch
            {
            }
        }
    }
}

Build project then click F5, result as below


Deploy an InfoPath 2010 Form with Managed Code to a Browser Enabled Sharepoint Document Library