views:

62

answers:

1

I'm surprised that I cannot find on the net a solution where I could manage views for content types. Do I really have to visit each task list with my browser to add/modify a view?

Is there any solutions available that would allow me to just define a view for content type and thus make this view available on all lists where content type is?

+1  A: 

Directly speaking, no, a view cannot be assigned to a content type. Lists are what hold an actual view collection, and the corresponding aspx page that is created with it. A view also has a dependent existence with its list: you cannot have a view that is not associated with a list. There is also no "event handler" for adding a content type to a list, either, so you can't have some automatic process that occurs whenever you add a content type to the list (and it would be cumbersome anyway as you'd have to attach the event handler to the list in the first place!).

This isn't to say you have to manually muck about in the UI to accomplish the task, though. Using the object model in something like a custom code workflow, you can sweep across your entire SPWeb and create a new view on each list that has the specified content type. All you need is a workflow with a single code activity, which iterates across all of the SPLists in SPWeb.Lists, and check if that SPList has the content type with the same name as your target content type. If it does, create a new SPView with the parameters you need. Since you cannot simply create one SPView and clone it, as an SPView must be associated with a list and cloning an SPView just clones it onto the same list, you'll have to run the whole SPView creation in each loop. But you only have to write it once, it's the system that'll have to run it multiple times. And by heavens, it'll certainly get that done a lot more productively than if you had to dance about in the UI for a few hours.

Simply run the workflow any time you need to reassert the existence of that SPView.

ccomet
Sure, that is achievable programmatically. Ok, it won't happen automatically when content types added to list, but thought maybe there is a solution that would allow you to define a view that automatically adds to those to current lists.
Janis Veinbergs