none
List Instance based on Asset library RRS feed

  • Question

  • HI Guys,

    There are three content type associate with Asset library but now i want to create a list instance based on Asset Library but i dont want these three content type i want only the custom content type i have created.

    I know how to do this in browser interface but i want to do in VS2010.

    I Know i have to create listinstace item type i did that then i dont know what i have to do in order to hide all out of box content types associate with asset library.

    Please assist me with this


    Thanks Ron
    • Moved by Anjali Ch -MSFT Wednesday, September 22, 2010 10:28 PM Routing to code sections (From:SharePoint 2010 - General Questions and Answers)
    Sunday, September 12, 2010 4:16 PM

Answers

  • Hi Ron,

     

    There are two possible ways which you can implement to achieve your requirement :

     

    1.       Create a desktop application in VS which will create a list instance based on the OOB “AssetLibrary” list definition and remove the existing content types and Add the custom content type to  the list instance and update the list instance object : The default content types included with the AssetLibrary definition are Audio, video and Image.

     

     

                SPSite oSite = new SPSite("http://blrs2r8-11");

                SPWeb oWeb = oSite.OpenWeb();

                SPListTemplate Otemplate = oWeb.ListTemplates["Asset Library"];

                SPList oList = oWeb.Lists[oWeb.Lists.Add("NewList", "New List from Code", Otemplate)];

     

                oList.ContentTypes["Video"].Delete();

                oList.ContentTypes["Audio"].Delete();

                oList.ContentTypes["Image"].Delete();

     

     

                SPContentType oCtype = oWeb.ContentTypes["Custom Content Type"];

                oList.ContentTypes.Add(oCtype);

     

                oList.Update();

     

     

     

    2.       The above shown code need to be run every time with different parameter for creating a list instance in SharePoint sites. So the better way would be to create custom list definition based on the OOB “AssetLibrary”.

     

    a.       The custom list definition based on the AssetLibrary cannot be created directly through VS 2010 SharePoint list definition project template as VS doesn’t give you the option to create a custom list definition based on Assetlibrary.

     

    b.       So you have to create the custom list definition based on the OOB Assetlibrary by copy paste the “Assetlibrary” folder under features directory.

     

    c.        Now delete the “AssetContenttypes.xml” and “AssetContentypes2.xml” as we don’t require them as this content types are already registered through OOB Assetlibrary and we no more required it too.  

     

    d.      Now modify the “Schema” of the custom list definition to remove the default content types attached with the list template and to include the custom content type. Change the feature Id, Title, Description and List template type as required and now deploy this custom list definition as feature and install and activate the feature. Now you will be provided with the new custom list template while creating list instance in UI itself which will create a Asset Library without OOB content types and with your custom content type.

     

    e.      You can refer this article to create a custom list definition based on OOB list definition http://msdn.microsoft.com/en-us/library/ms466023(v=office.12).aspx

     

     

    Both works as wonder .


    AnjaliCH-MSFT
    • Marked as answer by Anjali Ch -MSFT Wednesday, September 29, 2010 5:54 PM
    Tuesday, September 28, 2010 8:20 PM

All replies

  • Hi Ron,

     

    There are two possible ways which you can implement to achieve your requirement :

     

    1.       Create a desktop application in VS which will create a list instance based on the OOB “AssetLibrary” list definition and remove the existing content types and Add the custom content type to  the list instance and update the list instance object : The default content types included with the AssetLibrary definition are Audio, video and Image.

     

     

                SPSite oSite = new SPSite("http://blrs2r8-11");

                SPWeb oWeb = oSite.OpenWeb();

                SPListTemplate Otemplate = oWeb.ListTemplates["Asset Library"];

                SPList oList = oWeb.Lists[oWeb.Lists.Add("NewList", "New List from Code", Otemplate)];

     

                oList.ContentTypes["Video"].Delete();

                oList.ContentTypes["Audio"].Delete();

                oList.ContentTypes["Image"].Delete();

     

     

                SPContentType oCtype = oWeb.ContentTypes["Custom Content Type"];

                oList.ContentTypes.Add(oCtype);

     

                oList.Update();

     

     

     

    2.       The above shown code need to be run every time with different parameter for creating a list instance in SharePoint sites. So the better way would be to create custom list definition based on the OOB “AssetLibrary”.

     

    a.       The custom list definition based on the AssetLibrary cannot be created directly through VS 2010 SharePoint list definition project template as VS doesn’t give you the option to create a custom list definition based on Assetlibrary.

     

    b.       So you have to create the custom list definition based on the OOB Assetlibrary by copy paste the “Assetlibrary” folder under features directory.

     

    c.        Now delete the “AssetContenttypes.xml” and “AssetContentypes2.xml” as we don’t require them as this content types are already registered through OOB Assetlibrary and we no more required it too.  

     

    d.      Now modify the “Schema” of the custom list definition to remove the default content types attached with the list template and to include the custom content type. Change the feature Id, Title, Description and List template type as required and now deploy this custom list definition as feature and install and activate the feature. Now you will be provided with the new custom list template while creating list instance in UI itself which will create a Asset Library without OOB content types and with your custom content type.

     

    e.      You can refer this article to create a custom list definition based on OOB list definition http://msdn.microsoft.com/en-us/library/ms466023(v=office.12).aspx

     

     

    Both works as wonder .


    AnjaliCH-MSFT
    • Marked as answer by Anjali Ch -MSFT Wednesday, September 29, 2010 5:54 PM
    Tuesday, September 28, 2010 8:20 PM
  • This is awesome thanks a lot

     


    Thanks Ron
    Wednesday, September 29, 2010 4:51 PM
  • I wish to do the same thing. But I am not very experience in Sharepoint customization. Would you mind explaining in more detail on exactly where to copy the Asset Library folder to the Visual Studio project?
    Thursday, September 8, 2011 11:46 AM