instructions on how to use

Mar 18, 2009 at 5:51 PM
 Hi Doug. Thanks for providing this. Looking at the sparse instruction set (did I miss something) and examing the xml files in the zip file I see it appears we use a series of xml <task> nodes
e.g.
<Tasks>
  <SPWebUrl>http://sydsrvvm0077:6868/test/</SPWebUrl>
  <ListName>List with lookup column</ListName>
  <FieldName>lookup value</FieldName>
  <LookupListName>lookup 1</LookupListName>
  <LookupListFieldName>Lookup Column</LookupListFieldName>
</Tasks>

I see where you put in the URL, the two lists and their columns.Now as to their exact usage:
 Hmm is the <Fieldname> the field on the list (where you will create the lookup column) that contains the value (or foreign key) to the list you want to lookup?
e.g
    <Tasks>
  <SPWebUrl>http://sydsrvvm0077:6868/test/</SPWebUrl>
  <ListName>Child-List</ListName>
  <FieldName>Mary</FieldName>
  <LookupListName>Parent-List</LookupListName>
  <LookupListFieldName>Child-Name</LookupListFieldName>
  </Tasks>
So a new column will be created in the list "Child-List", and for each <task> node, taking the value of <FieldName>=Mary here to find the associated list item in the Parent-List Child-Name column that has the value of 'Mary' and create the lookup in Child-List to this item in Parent-List?
thanks in advance!

Ray
ps and I gather run the exe in the same dir as the xml files - I'll give it a go and see what it does. Some documentation is always good though.
Mar 18, 2009 at 5:52 PM
Ooops slight mistake, the <FieldName> should be "Child-Name" in the above example and one instance/item in this column would have the value of "Mary".
Ray
Coordinator
Apr 17, 2009 at 9:04 AM
Firstly, thank you for using the tool.

Yes, I have to admit I was a little lazy on providing document on this one! I have been very busy with work :(

So a quick answer:
<Tasks>
  <SPWebUrl>http://locationOfYourApp</SPWebUrl>
  <ListName>Name of List that looks to Master list for selectable values</ListName>
  <FieldName>Name of Field that looks to Master List field for selectable values</FieldName>
  <LookupListName>Name of Master List</LookupListName>
  <LookupListFieldName>Name of Field from Master List</LookupListFieldName>
  </Tasks>

More:

Furthermore the actual list names can be either:
Display Name, Internal Name, the relative URL in bold (eg. Some%20thing in /Lists/Some%20thing)

The actual field names can be either:
Display name, Internal name.

For example:
<Batch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Tasks>
    <SPWebUrl>http://localhost/sites/test</SPWebUrl>
    <ListName>A Test List</ListName>
    <FieldName>Fruit</FieldName>
    <LookupListName>All Fruits</LookupListName>
    <LookupListFieldName>Title</LookupListFieldName>
  </Tasks>
  <Tasks>
    <SPWebUrl>http://localhost/sites/test</SPWebUrl>
    <ListName>A Test List</ListName>
    <FieldName>Shop</FieldName>
    <LookupListName>All Shops</LookupListName>
    <LookupListFieldName>Title</LookupListFieldName>
  </Tasks>
</Batch>

The code I've used to retrieve lists is as follows - there's an error I just found in the catch segment - but I'll fix it in the code in the next release:
public static SPList GetList(string SPWebUrl, string listName)
        {
            SPList returnList = null;
            using (SPSite site = new SPSite(SPWebUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        returnList = web.Lists[listName];
                    }
                    catch
                    {
                        try
                        {
                            returnList = web.GetList(@"/Lists/" + listName.Replace(" ", "%20"));
                        }
                        catch
                        {
                            //Next line should be something else, otherwise method will throw another error.... in this case we should just let it be null as it did not find the list
                            //returnList = web.Lists[listName];
                        }
                    }
                }
            }

            return returnList;
        }


The code I've used to get fields is as follows:
public static SPField GetField(string SPWebUrl, string listName, string fieldName)
        {
            SPList list = null;
            SPField field = null;
            using (SPSite site = new SPSite(SPWebUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        list = web.Lists[listName];
                    }
                    catch
                    {
                        list = web.GetList(@"/Lists/"+listName.Replace(" ","%20"));
                    }
                    try
                    {
                        field = list.Fields.GetFieldByInternalName(fieldName);
                    }
                    catch
                    {
                        try
                        {
                            field = list.Fields.GetField(fieldName);
                        }
                        catch
                        {
                            field = list.Fields[fieldName];
                        }
                    }
                }
            }

            return field;
        }


I hope this helps.

Doug
http://sharepointsix.blogspot.com