Monday 8 October 2012

Infopath 2010 Drop-Down List Box (Get choices from fields in this form)

Binding Dropdown in infopath form load without using Data Connections ( Dropdown [Get choices from fields in this form]) using code behind.

  • Go to Infopath form, Add one Group (like test),set properties -check (Repeating).
  • Add two fields (like test_displayname and test_value) under Group.
  • Add one Dropdown,set properties (Get choices from fields in this form).
  • set the value as Group [like test_displayname and test_value].
  • go to on form load events write the code.
public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            XPathNavigator myRootNode = MainDataSource.CreateNavigator();
            XPathNavigator userNode = myRootNode.SelectSingleNode("/my:myFields/my:test", NamespaceManager);
            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList userlist = web.Lists["Departments"];
                     SPListItemCollection usercollection = userlist.GetItems();
                    if (usercollection.Count > 0)
                    {
                        foreach (SPListItem item in usercollection)
                        {
                            XPathNavigator newNode = null;
                            newNode = userNode.Clone();
                            newNode.SelectSingleNode("/my:myFields/my:test/my:test_displayname", this.NamespaceManager).SetValue(item.Title);
                            newNode.SelectSingleNode("/my:myFields/my:test/my:test_value", this.NamespaceManager).SetValue(item.Title);
                            userNode.InsertAfter(newNode);
                            newNode = null;
                        }
                        userNode.DeleteSelf();
                        userNode = null;
                    }
                }
            }

How to submit data from an InfoPath 2010 form to SharePoint 2010 List, using web service.

Please see the below url :

It's help to make insert item in sharepoint list using web services.

http://geekswithblogs.net/KunaalKapoor/archive/2012/04/30/how-to-submit-data-from-an-infopath-2010-form-to.aspx

Write html (like Hyper Link) in RichText Box in Infopath 2010 for Sharepoint list data.

1. Take (field1) one Richtext box and  (txturl) one text box fields.
2. On Form Load, Bind data connection toTextBox Controls.
3. Go to Infopath 2010 Form load event, write the code.

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
XPathNavigator attachmentNav = MainDataSource.CreateNavigator();
string url = attachmentNav.SelectSingleNode("/my:myFields/my:txturl", NamespaceManager).Value;
attachmentNav.SelectSingleNode("/my:myFields/my:field1", NamespaceManager).InnerXml = "<p xmlns='http://www.w3.org/1999/xhtml'>" + url + "</p>";
}

In ulr=" Welcome to the sharepoint 2010 with  <a  href='http:/www.google.com'>Infopath 2010</a>

Example: Welcome to the sharepoint 2010 with Infopath 2010


Make Document Set using infopath code in sharepoint 2010.

1.First create one Document Library and go to library sittings.
2.Open Advanced setting, then click "Yes" Allow management of centent types.
3.then Add from existing site content types , select Document Set.
4.Go to Infopath 2010, add one check box write code one change event in check box.

            XPathNavigator myRootNode = MainDataSource.CreateNavigator();
             myRootNode.SelectSingleNode(" /my:myFields/my:field4", NamespaceManager).SetValue("rintu");
            try
            {
               
                SPWeb web = SPContext.Current.Web;
                myRootNode.SelectSingleNode(" /my:myFields/my:field4", NamespaceManager).SetValue(web.Url.ToString());
                SPList list = web.Lists["BriefingDoc"];
                string sguid = System.Guid.NewGuid().ToString();
                web.AllowUnsafeUpdates = true;
                string sDocsetName = string.Empty;
                sDocsetName = "Document Set";
                DocumentSet ds = DocumentSet.Create(list.RootFolder, sguid, list.ContentTypes[sDocsetName].Id, null, true);
                web.AllowUnsafeUpdates = false;
                string DocUrl = ds.WelcomePageUrl.Replace("Document Set", "Document%20Set");
                myRootNode.SelectSingleNode("/my:myFields/my:field2/@my:field3", NamespaceManager).SetValue(DocUrl);

            }
            catch (Exception ex)
            {
                myRootNode.SelectSingleNode("/my:myFields/my:DatadeTérminoMessage", NamespaceManager).SetValue(ex.Message);
            }
            }

5.see that one hyper link is created, click that and upload the documents.