Quantcast
Channel: Cameron Dwyer – Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions
Viewing all articles
Browse latest Browse all 114

How to create a custom SharePoint list definition using Visual Studio 2012

$
0
0

In this article you will learn how to create a custom list definition (not a list instance) using the Visual Studio 2012 visual designer with step-by-step with screenshots.

In Visual Studio 2012 select File | New Project

Select Templates | Visual C# | Office/SharePoint | SharePoint 2013 – Empty Project

01-sharepoint-2013-how-to-custom-list-definition-vs2012-new-list-project-cameron-dwyer

If you don’t see this type of project available then you may need to download and install the Microsoft Office Developer Tools for Visual Studio 2012

Provide a name and location for the project/solution and OK

In the SharePoint Customization Wizard Prompt, configure the server to use for developing/debugging. If possible you will want to try and achieve a Sandboxed solution over a Farm Solution due to it’s ability to be able to be reused in more scenarios requiring less permission is the SharePoint environment.

02-sharepoint-2013-how-to-custom-list-definition-vs2012-site-trust-level-cameron-dwyer

Once the new solution has been created, we can use the new Visual Designer to create the List Definition. Right click the project in the solution explorer and select Add | New Item

03-sharepoint-2013-how-to-custom-list-definition-vs2012-add-new-item-cameron-dwyer

Select Visual C# Items | Office/SharePoint | List, provide a name and click OK

04-sharepoint-2013-how-to-custom-list-definition-vs2012-add-new-office-item-list-cameron-dwyer

Provide a display name for the list. We just want to create a list definition, not an instance of the list; This isn’t an option so what we do instead is go with the “Create a customizable list template and a list instance of it” and we will make some mods to the generated project files to remove the list instance so we are just left with the definition.

05-sharepoint-2013-how-to-custom-list-definition-vs2012-choose-list-settings-cameron-dwyer

You should now see the list instance and definition files in solution explorer.

06-sharepoint-2013-how-to-custom-list-definition-vs2012-instance-definition-files-cameron-dwyer

If you select the SettingsProfile in the solution explorer you will get the new List Visual Designer. Notice the “List” tab, this represents the instance of the list.

07-sharepoint-2013-how-to-custom-list-definition-vs2012-list-visual-designer-cameron-dwyer

Since we only want the list definition, we are going to delete the list instance files from solution explorer. Select SettingProfileInstance, right-click and Delete.

08-sharepoint-2013-how-to-custom-list-definition-vs2012-delete-instance-files-cameron-dwyer

You should now be left with just the list definition, the “List” tab will now be greyed out.

09-sharepoint-2013-how-to-custom-list-definition-vs2012-list-instance-removed-cameron-dwyer

We can now get on with creating the list definition and there are plenty of articles out there on the finer points of doing this. Here are some for reference:

http://roykimsharepoint.wordpress.com/2013/05/24/visual-studio-2012-list-and-content-type-designer-hands-on-observations/

http://msdn.microsoft.com/en-us/library/ee231593.aspx

http://www.skylinetechnologies.com/Blog/Article/76/Creating-Lists-in-SharePoint-Using-Visual-Studio-2012.aspx

 

Just for completeness if you are following this through I’ve added a couple of columns to my definition.

20-sharepoint-2013-how-to-custom-list-definition-vs2012-columns-defined-cameron-dwyer

Now lets deploy it to SharePoint to make sure it works

Double click the Feature in solution explorer to bring up the feature visual designer and package explorer

Here you can set options such as how the feature appears and it’s scope. For our purposes just confirm the items in the feature include just the list definition files.

10-sharepoint-2013-how-to-custom-list-definition-vs2012-packaging-explorer-cameron-dwyer

Now select the project, right-click and Deploy

11-sharepoint-2013-how-to-custom-list-definition-vs2012-deploy-solution-cameron-dwyer

Once the solution has been deployed I’m going to navigate to my site in a browser and verify that the new solution has been deployed and the feature activated (by default the solution is deployed and activated, and the feature is scoped at a web level and activated). You should see messages in the Visual Studio status bar to this effect during the deployment.

12-sharepoint-2013-how-to-custom-list-definition-vs2012-solutions-cameron-dwyer

13-sharepoint-2013-how-to-custom-list-definition-vs2012-verify-solution-deployed-cameron-dwyer

14-sharepoint-2013-how-to-custom-list-definition-vs2012-site-features-cameron-dwyer

15-sharepoint-2013-how-to-custom-list-definition-vs2012-verify-feature-activated-cameron-dwyer

Everything is now is place for us to create an instance of the list from the definition, so I’ll create a new app and select our Widget Settings Profile app (list definition).

17-sharepoint-2013-how-to-custom-list-definition-vs2012-add-list-instance-cameron-dwyer

Provide a name for the new list instance based on our custom list definition.

18-sharepoint-2013-how-to-custom-list-definition-vs2012-new-list-based-on-definition-cameron-dwyer

We can now create items in the list and we see our columns coming through that were defined in the custom list definition.

19-sharepoint-2013-how-to-custom-list-definition-vs2012-new-item-in-custom-list-cameron-dwyer

Job complete, in this article we went through creating a list definition using the Visual Studio 2012 SharePoint 2013 List project template. We manually deleted the default list instance files so that we were just left with the list definition in our solution.



Viewing all articles
Browse latest Browse all 114

Trending Articles