how to programetically get the type (TemplateType) of a Library using the item url
-
09-12-2019 - |
Question
Imagine if you have image url which is existing within a site collection in Sitecollectionimages
library: testserver/Sitecollectionimages/image.jpg
How can I get the TemplateType (which kind of library is this for e.g. Type 109
is for Picture Library) of this library using the image url?
Update: I will always have an absolute URL of the image.
Solution
using (SPSite site = new SPSite(<siteUrl>)
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.GetList(<imageUrl>);
SPListTemplateType templateType = list.BaseTemplate;
int templateTypeInt = (int) templateType;
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange