Populating InfoPath 2007 Dropdown with Sharepoint 2007 Title text(not urls)

L

lgwapnitsky

I have a Links library on my SP site for which I would like to use the
link titles as a dropdown option in an infopath form. When I try to
access the list items, they are reported to IP in the form of (http://
link.whatever.com/abcd, abcd). I only need the portion after the
comma to be in the dropdown.

Is this possible? I'm not a daily .NET programmer, so please be
understanding if I ask a lot of "stupid" questions.

Regards,
Larry
 
L

lgwapnitsky

FYI - Here's my code, adapted from S.Y.M. Wong-A-Ton's notes at
http://www.bizsupportonline.net/inf...populate-drop-down-list-box-infopath-2007.htm.
My sharepoint list has multiple items in it, but it is repeating one
item in the drop-down.

using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;

namespace InfoPathFormTemplate1
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled
forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }

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

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

// XPathNodeIterator players =
DataSources["players"].CreateNavigator().Select(
// "//player", NamespaceManager);
//
// foreach (XPathNavigator player in players)
// {
// string number = player.SelectSingleNode("number",
NamespaceManager).Value;
// string name = player.SelectSingleNode("name",
NamespaceManager).Value;
// AddItem(number, name);
// }

XPathNodeIterator ProjectSites =
DataSources["ProjectSites"].CreateNavigator().Select("/dfs:myFields/
dfs:dataFields/dfs:project_Sites", NamespaceManager);

foreach (XPathNavigator ProjectSite in ProjectSites)
{
string number = ProjectSite.SelectSingleNode("/
dfs:myFields/dfs:dataFields/dfs:project_Sites/@Office",
NamespaceManager).Value;
string name = ProjectSite.SelectSingleNode("/
dfs:myFields/dfs:dataFields/dfs:project_Sites/@Site_Name",
NamespaceManager).Value;
AddItem(number, name);
}

RemoveFirstItem();
}

private void RemoveFirstItem()
{
XPathNavigator DOM =
DataSources["options"].CreateNavigator();
XPathNavigator group1 = DOM.SelectSingleNode("//options",
NamespaceManager);
XPathNavigator field1 = DOM.SelectSingleNode("//options/
option", NamespaceManager);
field1.DeleteSelf();
}

private void AddItem(string itemId, string itemName)
{
XPathNavigator DOM =
DataSources["options"].CreateNavigator();
XPathNavigator group1 = DOM.SelectSingleNode("//options",
NamespaceManager);
XPathNavigator field1 = DOM.SelectSingleNode("//options/
option", NamespaceManager);
XPathNavigator newNode = field1.Clone();
newNode.SelectSingleNode("value").SetValue(itemId);

newNode.SelectSingleNode("displayname").SetValue(itemName);
group1.AppendChild(newNode);
}
}
}
 
L

lgwapnitsky

FYI - Here's my code, adapted from S.Y.M. Wong-A-Ton's notes athttp://www..bizsupportonline.net/infopath2007/programmatically-fill-po....
My sharepoint list has multiple items in it, but it is repeating one
item in the drop-down.

using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;

namespace InfoPathFormTemplate1
{
    public partial class FormCode
    {
        // Member variables are not supported in browser-enabled
forms.
        // Instead, write and read these values from the FormState
        // dictionary using code such as the following:
        //
        // private object _memberVariable
        // {
        //     get
        //     {
        //         return FormState["_memberVariable"];
        //     }
        //     set
        //     {
        //         FormState["_memberVariable"] = value;
        //     }
        // }

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

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

//            XPathNodeIterator players =
DataSources["players"].CreateNavigator().Select(
//            "//player", NamespaceManager);
//
//            foreach (XPathNavigator player in players)
//            {
//                string number = player.SelectSingleNode("number",
NamespaceManager).Value;
//                string name = player.SelectSingleNode("name",
NamespaceManager).Value;
//                AddItem(number, name);
//            }

            XPathNodeIterator ProjectSites =
DataSources["ProjectSites"].CreateNavigator().Select("/dfs:myFields/
dfs:dataFields/dfs:project_Sites", NamespaceManager);

            foreach (XPathNavigator ProjectSite in ProjectSites)
            {
                string number = ProjectSite.SelectSingleNode("/
dfs:myFields/dfs:dataFields/dfs:project_Sites/@Office",
NamespaceManager).Value;
                string name = ProjectSite.SelectSingleNode("/
dfs:myFields/dfs:dataFields/dfs:project_Sites/@Site_Name",
NamespaceManager).Value;
                AddItem(number, name);
            }

            RemoveFirstItem();
        }

        private void RemoveFirstItem()
        {
            XPathNavigator DOM =
DataSources["options"].CreateNavigator();
            XPathNavigator group1 = DOM.SelectSingleNode("//options",
NamespaceManager);
            XPathNavigator field1 = DOM.SelectSingleNode("//options/
option", NamespaceManager);
            field1.DeleteSelf();
        }

        private void AddItem(string itemId, string itemName)
        {
            XPathNavigator DOM =
DataSources["options"].CreateNavigator();
            XPathNavigator group1 = DOM.SelectSingleNode("//options",
NamespaceManager);
            XPathNavigator field1 = DOM.SelectSingleNode("//options/
option", NamespaceManager);
            XPathNavigator newNode = field1.Clone();
            newNode.SelectSingleNode("value").SetValue(itemId);

newNode.SelectSingleNode("displayname").SetValue(itemName);
            group1.AppendChild(newNode);
        }
    }



}- Hide quoted text -

- Show quoted text -

Anyone have any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top