I'm working on a site, where a web part I'm building takes the name of a custom list type as a property when editing the web part settings.
The "List" that this visual web-part is designed to display, comes from a List template that is also installed into SP (Currently 2010).
Iv'e already figured out how to tell that the list assigned is "GenericList", but what I actually need to know is the specific list type. I'm obtaining this property from the SPList object type that I have for the list specified by the user.
In case anyone wants code... here you go.
errorMesg.Visible = false;
if (string.IsNullOrEmpty(ListName))
{
errorMesg.Text = "Please assign the name of your JobsQueue list in the web part settings, under list settings";
errorMesg.Visible = true;
return;
}
SPWeb web = SPContext.Current.Web;
try
{
SPList jobsQueueList = web.Lists[ListName];
if(jobsQueueList.BaseTemplate == SPListTemplateType.GenericList && <WHAT DO I PUT HERE TO SAY AND IS A JOBSQUEUE TYPE>)
}
catch (ArgumentException)
{
errorMesg.Text = $"The List name '{ListName}' does not exist in your current site, please ensure settings are correct.";
errorMesg.Visible = true;
}
finally
{
web.Dispose();
}
However, I think Iv'e explained ok what I'm trying to achive (Well I hope I have any way!!! :-) )
In my solution, there are several custom List Templates added, and I need to know that the user has selected EG "JobsQueue" type, rather than "PaymentQueue" type.
All I can see so far is "list.BaseTemplate" which is how I know that the list is a Generic/Custom type, now I just need to figure out which custom type.
I'm doing this for good error handling, so that my visual component doesn't crash if a List type is assigned that doesn't have the correct list structure that it expects.
Any pointers on the best way to this greatly accepted.
Cheers Shawty
Update
Iv'e been talking to a good friend of mine, who I know, knows Sharepoint very well, but he didn't have time to take me through an entire example, He suggested that I might want to try 1 of 2 things:
1) Add a taxamony metadata field on the list definition (I'm developing these lists and Web parts in Visual Studio 2015), then when I check the table type, just simply look for the metadata marker, to know the list type.
2) Alter the list type ID's in feature-elements.xml and then look for those ID's in the base type ID to determine the list type.
I don't know what either of those 2 options are, and as I say he didn't have time to explain to me, so if these ideas trigger anything for anyone before I get chance to hunt the knowledge down, please feel free to comment :-)
Update 2 (Approx 26+ hours later)
So after much more reading, and researching, and breaking things then fixing them again.
I think I've found what to me seems like a better method than scanning field names, I'll add an answer for it soon.