4

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.

3
  • Is this image url an absolute url?
    – Matthias
    May 24, 2012 at 11:16
  • why dont use, SP solution generator and see the lists and document library associated to that specific site/sitecollection :) May 24, 2012 at 12:05
  • Matthias, it will always be be an absolute url
    – Geek
    May 24, 2012 at 12:35

1 Answer 1

4
using (SPSite site = new SPSite(<siteUrl>)
{
  using (SPWeb web = site.OpenWeb())
  {
    SPList list = web.GetList(<imageUrl>);
    SPListTemplateType templateType = list.BaseTemplate;       
    int templateTypeInt = (int) templateType;
  }
}
3
  • Mathias, will it work for absolute url?
    – Geek
    May 24, 2012 at 12:41
  • will it work for image url like this ? testserver/Sitecollectionimages/image.jpg
    – Geek
    May 24, 2012 at 22:57
  • +1, it should work as expected May 24, 2012 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.