I have sandbox solution which has 2 features (both are sitecollection level features) I am activating both feature using same USER.
feature 1 : that uploads .stp files to _catalogs/lt folder via module file
feature 2 (is dependent on feature 1) : it will get all .stp file via .GetCustomListTemplates(spweb) method from _catalogs/lt, but there are no files coming in here is my code
using (SPSite mySite = properties.Feature.Parent as SPSite)
{
using (SPWeb spWeb = mySite.OpenWeb())
{
spWeb.AllowUnsaf开发者_StackOverflow社区eUpdates = true;
SPListTemplateCollection listTemplates = mySite.GetCustomListTemplates(spWeb);
}
}
listTemplates has no .stp files.it is coming out empty.
pls help me ...
Does your list template derive from one of the default list templates like "Discussion Board"? I noticed that when I tried to do the following I encountered the same problem as you:
- Save a SharePoint 2007 "Discussion Board" list as a list template
- Use the method in this blog to convert the template to SharePoint 2010
- Upload the template to my SharePoint 2010 site
I noticed that the default "Discussion Board" list template was not even an option for creating a new list in SharePoint 2010. Therefore I went to the site features and and turned on the "Team Collaboration Lists" just to enable the default "Discussion Board" list template. After doing that both the default "Discussion Board" list template and my custom "Bulletin Board" template showed up when I went to create a new list. Then I went to my powershell script and noticed that GetCustomListTemplates returned my custom template. I'm assuming that means the C# should work as well.
Here is the list from the old SharePoint 2007 website:
Here is the collaboration feature that enables the "Discussion Board" list template in the new SharePoint 2010 website:
Here is the menu for creating a new list in the new SharePoint 2010 website AFTER enabling the team collaboration lists feature:
As you can see the "BulletinBoard" image is the same as the "Discussion Board" image so SharePoint probably couldn't use the "BulletinBoard" template because the "Discussion Board" template was not yet installed.
If you use the Record Center as the template for your root website in SharePoint 2010, GetCustomListTemplates() will always return 0 (zero).
There is some weird bug that makes this happen.
Here is code that you can try running in the SharePoint PowerShell. The return value for GetCustomListTemplates($web).Count will be zero if you have the root web made from the Record Center template.
$site = get-spsite("http://localhost")
$web = $site.RootWeb
$list = $web.Lists["TestDocLibrary"]
$list.SaveAsTemplate("MyListTemplate.stp", "MyListTemplate", "My List Template", $false)
$site.GetCustomListTemplates($web).Count
More information can be found at the following web pages:
- http://social.msdn.microsoft.com/Forums/ar/sharepoint2010general/thread/c5455a27-360a-465c-91d5-f81beeac6789
- http://sharepointrecordsmanagement.com/2011/02/
Good luck! - Jason
精彩评论