Please see the code
sing 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
{
}
}
}
}
No comments:
Post a Comment