I want to identify the splist is a sharepoint calendar or not before i start my function.
So how to identify a sharepoint calendar or it is just a sharepoint list?
Check that SPList is Calendar(Events) list or not:
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists.TryGetList("Calendar1");
if (list != null)
{
if (list.BaseTemplate == SPListTemplateType.Events)
{
//It is Calendar list
}
}
web.AllowUnsafeUpdates = false;
}
}
You can use below code to check list template type using C#
using (SPSite site = new SPSite("<server url>"))
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists.TryGetList("My List");
if (list != null)
{
if (list.BaseTemplate== SPListTemplateType.Events)
{
//Call function
}
}
}
}
Hope this will help you!
list.BaseType
will return GenericList
.. Use list.BaseTemplate
Commented
Jan 5, 2017 at 4:38
We can also achieve this by PnP JS Core library. Here I have provided two options to identify whether the given list is calendar type or now.
Calendar List's Base Template is 106
Option 1: The options 1 checks the list is calendar type or not during the request and returns if anyone found with the condition
function isCalendartype(lstName) {
$pnp.sp.web.lists.filter("(Title eq '" + lstName + "') and (BaseTemplate eq 106)").get().then(function(res) {
if (res.length === 0)
console.log(lstName + ' list is not a calendar type');
else
console.log(lstName + ' list is a calendar type');
});
}
isCalendartype('CalendarList');
Option 2: This options gets the list information based on title and then check whether the list is calendar type or not.
function isCalendartype(lstName) {
$pnp.sp.web.lists.getByTitle("DevEvents").get().then(function(res) {
if (res.BaseTemplate === 106)
console.log(lstName + ' list is a calendar type');
else
console.log(lstName + ' list is not a calendar type');
});
}
isCalendartype('CalendarList');
I hope the above given helps you to check in client side.
Below can be done using REST API
executor.executeAsync({
url: "<app web url>/_api/SP.AppContextSite(@target)/web
/lists(guid'51925dd7-2108-481a-b1ef-4bfa4e69d48b')/BaseTemplate
?@target='<host web url>'",
method: "GET",
headers: { "accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
});
BaseTemplate Int32 R Yes
Gets the list definition type on which the list is based. Represents a ListTemplateType value. See ListTemplateType
in the .NET client object model reference for template type values.
BaseTemplate for Calendar is 106. For other template type refer here
in Sharepoint We have So many Types Of lists There are 1)CustomList 2) Document Library list 3) picture Library list 4) Announce ment list 5) task list
like that if you want to add any list at right corner of your site a gear option will come click on that and add an app you will add which list you want.and finally i am showing difference between calender list And Customelist
Calender list View:-
customList View:-