简体   繁体   中英

SharePoint 2010 - How can we get list template name from the list if the list is created from ListTemplate

We have created a few list templates in the sharepoint and created the lists with using List Templates. Here is the example,

ListTemplates

  1. ListTemplate1
  2. ListTemplate2
  3. ListTemplate3

Lists created following way,

List1 is created using ListTemplate1
List2 is created using ListTemplate2
List3 is created using ListTemplate3

And later user created List4 using ListTemplate1,

Now we are trying to identify which list is created by which template. But we couldn't identify the listtemplate properly. It is always coming as ListTemplate1 in few site colelctions, ListTemplate2 is the few site collections

Can anyone help me to get the correct listtemplate name for list?

Below is the Powershell code I have used to get list template for particular list.

$sourceWebURL = "WebUrl"
$sourceListName = "listname"

$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceList.TemplateFeatureId

Please try this approach, in my case it returned the correct list templates



    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell";
    }

    $_URL = "URL";
    $SPWeb = Get-SPWeb $_URL;

    $SPList = $SPWeb.Lists["LIST_NAME"];
    $listTemplate = $SPWeb.ListTemplates | ? {$_.FeatureId -eq $SPList.TemplateFeatureId};
    $listTemplate.Name;
    $listTemplate.FeatureId;

let me know if it was of any help

* UPDATE * here is a small script to get all templates from web



     if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell";
    }

    $_URL = "[URL]";
    $SPWeb = Get-SPWeb $_URL;

    foreach($templates in $SPWeb.ListTemplates){
        $templates.Name;
        $templates.FeatureId;
        $templates.InternalName;
        $templates.SchemaXml;
    }

What You could do is to check if maybe no property (check also other props, not only the ones I mention in the script, You can always just check $tempplate object to get all) is different for this 3 templates You have. Maybe FeatureId is the same but check also the featureId in SchemaXml, maybe there is different. If all properties are the same what You could do is to update the 'description' property for the first template with this featureId like 'temp1' and second with value 'temp2' and so on. After that You can check if template You get from the list has always the same description. Probably it will be the same, if Yes then my next approach would be to try to update the featureId but please be aware that it is rather not recommended approach and may produce some errors. Maybe a better idea would be to try to reproduce the error on some dev environment and try to fix it there with changing the featureId.

Also You can check the SPExport and SPImport on list to maybe try to export those list and import them on some dev environment and try to fix this problem there.

Sample script to get template name for your reference.

$sourceWebURL = "http://sp10/"
$sourceListName = "ListBasedonTemplate1"

$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceList.TemplateFeatureId
$listTemplate=$spSourceWeb.Site.GetCustomListTemplates($spSourceWeb) | ? {$_.FeatureId -eq $spSourceList.TemplateFeatureId}
$listTemplate[0].Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM