Reputation: 611
Hi I am querying the Sharepoint Lists using the Sharepoint Library in .net. I noticed that there is more than one title field. How can I get the user defined title field?
SPListItem item = myItemCollection[i];
item["Title"] <- provides me the wrong title field
Is this a known issue, any work around? Thanks
However if I go into my list settings and rename the column from Title to Article. And do the following it works:
SPListItem item = myItemCollection[i];
item["Article"] <- provides me the wrong title field
Upvotes: 2
Views: 1223
Reputation: 748
Run this in a console application. More than likely your problem is related to difference in Display and Internal name as mentioned above. Something to note: even when you create a custom list and rename the default "Title" field the internal name never changes from "Title".
using (SPSite siteCollection = new SPSite("~~~~ Your site URL here ~~~~"))
{
using (SPWeb site = siteCollection.RootWeb)
{
foreach (SPField f in site.Lists["~~~~ Your list name here ~~~~"].Fields)
{
Console.WriteLine(f.InternalName + " | " + f.Title);
}
}
}
Console.ReadLine();
Upvotes: 2
Reputation: 1907
If you have two items that have the same display name but with different internal names then SharePoint most likely added elements to differentiate the fields. I would put a break point on the list item and look through the xml code for the item (copy paste it into VS). Then you may be able to see how the fields are different.
If that doesn't work then store the GUID and use that instead.
Upvotes: 0
Reputation: 16780
You're looking for ["LinkTitle"]
or ["Name"]
- most likely the former.
Upvotes: 0