Managing views for content types (or adding a view to multiple lists)

I am surprised that I can’t find a solution on the net where I can manage the views for content types. Do I really need to visit each task list with my browser in order to add / change the view?

Are there any solutions that would allow me to simply define the view for the content type and thus make that view available in all lists where the content type is?

+4
source share
2 answers

Frankly, no , a view cannot be assigned to a content type. Lists are what contain the actual collection of views and the corresponding aspx page that is created with it. The view also has a dependent existence with its list: you cannot have a view that is not associated with the list. There is also no “event handler” for adding a content type to a list, so you cannot have any automatic process that occurs whenever you add a content type to a list (and that would be inconvenient anyway as you need attach the event handler to the list first!).

This does not mean that you need to manually disconnect in the user interface in order to complete the task. - , SPWeb . , - , SPLists SPWeb.Lists , SPList , . , SPView . SPView , SPView , SPView , SPView . , , . , , , , .

, SPView.

+3

#, . , .

-, SharePoint 2010, .

private void CreateView(string strViewName)
{
    try
    {
        string fieldName = //Get Field Internal Name
        var docquery = "<Where><Eq><FieldRef Name='" + fieldName.ToString() + "' /><Value Type='Choice'>" + strViewName.ToString() + "</Value></Eq></Where>";
        System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
        viewFields.Add("Type");
        viewFields.Add("Name");
        viewFields.Add("Modified");
        viewFields.Add("Modified By");
        viewFields.Add(fieldName.ToString());
        oViewCollection.Add(strViewName, viewFields, docquery, 100, true, false);
        web.Update();
    }
    catch (Exception e)
    {
        throw new SPException(e.Message.ToString());
    }
}
0

Source: https://habr.com/ru/post/1744451/


All Articles