Programmatically creating views for a SharePoint discussion forum



As you can see I'm still working on sites, lists and views and I ran into another challenge.


It started out very basic. I wanted to create a discussion forum list on a site.


// Create new list

listGuid = newWeb.Lists.Add("Forum", "ForumDescription", "Forum", "00BFEA71-6A49-43FA-B535-D15C05500108", 108, "", SPListTemplate.QuickLaunchOptions.Off);

SPList forumList = newWeb.Lists[listGuid];


After succesfully creating the forum list I wanted to add a custom view to the list. That seemed to be easy enough as well.


// Add an extra view to the list

viewFields = new StringCollection();




newView = forumList.Views.Add("Portal View", viewFields, "", 100, true, false);



Unfortunately creating a view using the code above causes the link on the title takes you to the forum list, instead of taking to the item for which you clicked the title. After doing some investigating via the user interface I found out that the subtle difference can be found in the View settings, under Folders. This setting is specific for the discussion forum. By default the choices "Show items inside folders" and "In all folders" is selected. When you change the second setting (Show this view:) to "In the top-level folder" the link on the title item behaves the way you expect and want it to behave.




Now the next challenge was to find out how to change the Folders settings using the object model. There is no property on the SPList or SPView object to change these settings, but after comparing the xml exports of the list with both settings I found out that there is a ContentTypeId property on the SPView object and that this was the only thing that changed between the two exports.


The way to set the "Show this view" setting to  "In the top-level folder" is by using this code. Notice the second to last line, that's the line that I added to achieve this.


// Add an extra view to the list

viewFields = new StringCollection();




newView = forumList.Views.Add("Portal View", viewFields, "", 100, true, false);

newView.ContentTypeId = new SPContentTypeId("0x012001");



So in the end the code you need to get the right settings for you discussion forum view is not difficult at all, the difficult part was finding out what code to use.

Comments -
  1. Gravatar

    Thanks Mirjam
    This is very helpful ..even I was also stuck on the same point and seemed very difficult to figure out the solution..

    It works absolutly fine for me..

    But now what if I want to change the setting as " In folders of content type Discussion" .where will I get the Content Type ID..any standard reference for the same available..?

  2. Gravatar

    Hi Sunil,

    The easiest way to find the correct content type ID is:
    * Create a view
    * Specify the "In folders of content type Discussion" filter
    * Save the view
    * Save the list as a template
    * Download the .stp file
    * Rename the .stp file to a .cab file
    * Extract the manifest.xml

    Do the same thing, but now select "In the top-level folder" and compare the manifest.xml files.
    This is how I originally found out what content type I needed for this post.

  3. Gravatar

    Thanks Mirjam..
    Apprecaite your help
    keep posting..

  4. Gravatar

    this was helpful. thanks. and for others reading this, in case you want "In Folders of Content Type : Discussion" , use the id "0x012002". If you do not use this id, the Flat and Threaded views will not show up when you click on a discussion list item (there will be no reply button and it will always default to the subject view).

  5. Gravatar

    Thanks for this code! This was driving me crazy.

  6. Gravatar

    If you had asked me to predict which brand would debut a new logo on its Fall 2017 runway, I wouldn't have guessed Fendi. The brand already has both an iconic logo print and logo hardware that longchamp outlet it has barely capitalized on during the recent resurgence of that look in the accessories market, but for Fall 2017, those things sit alongside the Fendi brand markers we all know and love from the 90s and mulberry replica handbags early 2000s. The new logo hardware is featured prominently on a slew of new flap bags, and it's an open circle with an F resting on its side at the bottom, as though it fell that way. The new replica designer handbags logo's best use by far is as the center of a flower made of leather petals on micro bags and bag charms, several of which made it to the runway alongside the larger bags. Fendi's Zucca logo fabric, which has long been mostly missing from the brand's bags, also figured prominently in several pieces, and now is the perfect time for it to be returning to favor among the label's bag designers.

  7. Gravatar

    You buy a commitment from manufacturers to meet their standards by maintaining the high quality running of your Rolex Watches.If you have any repair needs in the future, you can return to the manufacturer or authorized dealer and be assured that your Original Omega Watches will be treated with the same care with which it was made.A Luxury Breitling Watches is more than just a wristwatch; This is a piece of 1:1 IWC that reflects your personality and personal style - and can be enjoyed for a lifetime.If you’re shopping Hermes handbags online or in a store, don’t be rushed into making a purchase.The buying Rolex Submariner Watches season is here and now is the time to buy you or your loved one a good Christmas gift

  8. Gravatar

    Hermes Handbags president for her specially designed a handbag, and to her name to name, this is the Replica Handbags,Your help in find out this in Breitling Wattches is very much appreciated. If you could send me more pictures of Rolex Daytona, I could see Rolex Watches Online that it is a nice band of watches that would be great.

  9. Gravatar

    Watch, watch. A tool that is worn on the wrist for timing. On social occasions, wearing a watch, usually means a strong sense of breitling replica time, rigorous style of work; and people who don't wear watches, or to ask others at the time people are always very much because it sniff at that time, the rolex replica concept is not strong. In formal social occasions, watches are often regarded as jewelry, usually only a ring can be worn for men, it is highly valued. Some people even stressed: "watches are not only men's jewelry, but also the rolex replica most important men's jewelry."

  10. Gravatar

    Création par programme de vues pour un forum de discussion SharePoint
    christian louboutin
    Christian Louboutin Sandals

  11. Gravatar

    Replica orologi sono indubbiamente chiamati i più eccellenti orologi in tutto il mondo in questo momento. orologi replica italiaTengono loghi straordinariamente efficaci, orologi lusso online scintillanti e creative. E 'la mostra più caldi sulla forza delle sue creazioni più significative.orologio replica omega Gli orologi replica non sono spettacoli costosi alla moda. Si tratta di uno dei più bei orologi cercando. Replica non solo orologi motivare i vostri metodi, ma anche dare un grande fiducia, orologi replica il rilassamento e sollievo a lungo. Ancora più importante, essi sono orologi molto popolare per gli uomini e le donne, in quanto non solo vi darà un enorme rispetto per se stessi, ma anche diminuire subito i tuoi sentimenti miserabili.


Leave a Reply


Please add 8 and 4 and type the answer here: