Friday, August 15, 2014

Creating two different default views for SharePoint List - part 1


Let's say you have one Document Library in SharePoint and in this library you have created custom Content Type called "DocCase", which is derived from Content Type "Folder" and it has its own custom metadata columns. "DocCase" is a container for documents, i.e. every document that is uploaded to this library is uploaded to one "DocCase". It is actually a Folder for my documents, but with my custom columns (metadata).

But, Content Type "DocCase" and documents that are uploaded to that "DocCase" have different metadata. I would like to set two different views (to show different metadata) for each of these Content Types.

NOTE: I am using "Doc Case" Content Type just as an example. This process of creating two default views can be applied to ordinary "Folder" Content Type, or any other Content Type that inherits "Folder" Content Type.


Soloution is to create two new views in SharePoint list. First view will be default, but only in top-level of our list, and the second will be default for "DocCase" Content Type in that list. This means that when you go to your list, view will show columns of "DocCase", and when you click on one of "DocCase", it will show columns of these documents (I hope you understand what I am trying to do here).

I am going to describe three ways of doing this:
1. In SharePoint list (GUI)
2. Using C# code in Visual Studio (following post)
3. Using List Definition in Visual Studio (following post 2)

1. In SharePoint list:

Go to your list and create new "Standard view". For a name of this view I wrote "DocCase view", but it can be anything you want. Check option "Make this view default view".

Choose the fields you would like to see in your view (this is just an example of my fields):

Go to section "Folders" and select option "In the top-level folder".

Now click Save. Our first view is done.

Now, you need to create second "Standard view" for documents. Name it as you wish and check the "Make this the default view" option.

Select desired fields (example of my fields):

Go to section "Folders" and select option "In folder of content type" and select your content type (in this case it is "DocCase".

Hit Save button, and that is it.

Now, when you go to your list (Documents in my case), default view "DocCase view" opens and shows our "DocCases" with their columns (Client Address, Client ID...).

But, when you click on one of the "DocCases" ("My New Doc Case"), it switches to the second view - "Docs" - and you can see that different columns appear (Created By, Created, Modified, Modified By...).

In my next posts (post2, post3), I am showing how to do the exact same thing programmatically.

1 comment: