Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>Anyone know how to change the ListViewWebPart in code programatically to remove the toolbar?</p> <p align=left> </p> <p align=left>I have tried something lke this:</p> <p align=left> </p> <p align=left> </p><font size=2> <p></font><font color="#008080" size=2>SPLimitedWebPartManager</font><font size=2> lMgr = </font></p> <p align=left><font size=2>oSPWeb.GetLimitedWebPartManager(Page_Aspx,  </font><font color="#008080" size=2>PersonalizationScope</font><font size=2>.Shared);</font></p> <p align=left><font color="#008080" size=2>ListViewWebPart</font><font size=2> wp = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)lMgr.WebParts[1];</p> <p>lvpart.Title = </font><font color="#800000" size=2>&quot;test&quot;</font><font size=2>;</p> <p>lvpart.ListViewXml = lvpart.ListViewXml.Replace(</font><font color="#800000" size=2>&quot;Standard&quot;</font><font size=2>, </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>);</font></p><font size=2> <p>System.Diagnostics.<font color="#008080" size=2>Debug</font><font size=2>.Print(lvpart.ListViewXml);</font></p> <p align=left><font size=2> //// Shows Toolbar Type = None</p></font> <p> </p> <p align=left>// update</p> <p align=left>lMgr.SaveChanges(lvpart);</p> <p align=left> </p> <p align=left>// Refresh Mgr</p> <p>lMgr = oSPWeb.GetLimitedWebPartManager(Page_Aspx, System.Web.UI.WebControls.WebParts.</font><font color="#008080" size=2>PersonalizationScope</font><font size=2>.Shared);</p> <p></font><font size=2>wp = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)lMgr.WebParts[1];</font></p> <p align=left><font size=2> </p> <p>System.Diagnostics.</font><font color="#008080" size=2>Debug</font><font size=2>.Print(lvpart.ListViewXml);</p> <p> </p> <p align=left>/// Shows Shows Toolbar Type = Standard</p> <p align=left>// But the Title gets updated!</p> <p align=left> </p> <p align=left> </p> <p>Is this the wrong path or is there an alternate method for doing this?  </p> <p align=left> </p> <p align=left>Its wierd.  </p> <p align=left>Is the Toolbar setting associated with the SPView  or  With the actual web part?</p> <p align=left> </p> <p align=left> </p> <p align=left>Thanks!!</p> <p align=left> </p> <p align=left></font> </p>© 2009 Microsoft Corporation. All rights reserved.Tue, 03 Nov 2009 01:23:50 Z96aac2dd-29fc-4e63-8730-9d1adc01b826http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#96aac2dd-29fc-4e63-8730-9d1adc01b826http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#96aac2dd-29fc-4e63-8730-9d1adc01b826Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>Anyone know how to change the ListViewWebPart in code programatically to remove the toolbar?</p> <p align=left> </p> <p align=left>I have tried something lke this:</p> <p align=left> </p> <p align=left> </p><font size=2> <p></font><font color="#008080" size=2>SPLimitedWebPartManager</font><font size=2> lMgr = </font></p> <p align=left><font size=2>oSPWeb.GetLimitedWebPartManager(Page_Aspx,  </font><font color="#008080" size=2>PersonalizationScope</font><font size=2>.Shared);</font></p> <p align=left><font color="#008080" size=2>ListViewWebPart</font><font size=2> wp = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)lMgr.WebParts[1];</p> <p>lvpart.Title = </font><font color="#800000" size=2>&quot;test&quot;</font><font size=2>;</p> <p>lvpart.ListViewXml = lvpart.ListViewXml.Replace(</font><font color="#800000" size=2>&quot;Standard&quot;</font><font size=2>, </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>);</font></p><font size=2> <p>System.Diagnostics.<font color="#008080" size=2>Debug</font><font size=2>.Print(lvpart.ListViewXml);</font></p> <p align=left><font size=2> //// Shows Toolbar Type = None</p></font> <p> </p> <p align=left>// update</p> <p align=left>lMgr.SaveChanges(lvpart);</p> <p align=left> </p> <p align=left>// Refresh Mgr</p> <p>lMgr = oSPWeb.GetLimitedWebPartManager(Page_Aspx, System.Web.UI.WebControls.WebParts.</font><font color="#008080" size=2>PersonalizationScope</font><font size=2>.Shared);</p> <p></font><font size=2>wp = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)lMgr.WebParts[1];</font></p> <p align=left><font size=2> </p> <p>System.Diagnostics.</font><font color="#008080" size=2>Debug</font><font size=2>.Print(lvpart.ListViewXml);</p> <p> </p> <p align=left>/// Shows Shows Toolbar Type = Standard</p> <p align=left>// But the Title gets updated!</p> <p align=left> </p> <p align=left> </p> <p>Is this the wrong path or is there an alternate method for doing this?  </p> <p align=left> </p> <p align=left>Its wierd.  </p> <p align=left>Is the Toolbar setting associated with the SPView  or  With the actual web part?</p> <p align=left> </p> <p align=left> </p> <p align=left>Thanks!!</p> <p align=left> </p> <p align=left></font> </p>Wed, 01 Aug 2007 11:18:34 Z2007-09-18T16:03:45Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#c4c2799a-5c80-45ef-9da6-c48714dba6a8http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#c4c2799a-5c80-45ef-9da6-c48714dba6a8rickchanghttp://social.msdn.microsoft.com/Profile/en-US/?user=rickchangUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p>Maybe something like this?</p> <p align=left>List.Views[<font color="#a31515" size=2>&quot;Name of View&quot;</font><font size=2>].Toolbar = </font><font color="#a31515" size=2>&quot;None&quot;</font><font size=2>;</p> <p>List.Views[</font><font color="#a31515" size=2>&quot;Name of View&quot;</font><font size=2>].Update();</p></font><font size=2></font> <p align=left><font face=Arial size=2></font> </p>Fri, 03 Aug 2007 15:32:43 Z2007-08-03T15:32:43Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#74a03660-124d-48d2-a5d3-f43ecec16c56http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#74a03660-124d-48d2-a5d3-f43ecec16c56Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>That of course will not work because Toolbar needs to be an HTML string. </p> <p align=left>Thanks for the &quot;Guess&quot;, I guess</p>Sun, 05 Aug 2007 11:26:14 Z2007-08-05T11:26:14Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#de3bf922-bdd8-4ceb-a50b-c88fe4f75b43http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#de3bf922-bdd8-4ceb-a50b-c88fe4f75b43Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>The only way to set the toolbar properties that I could find is updating the content database directly.  I was hoping this kind of solution would not be needed in the MOSS 2007 but oh well.</font></p> <p align=left> </p>Wed, 29 Aug 2007 16:03:21 Z2007-09-18T16:03:31Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#751f119c-1c4e-47ab-b197-2e2d305ffa3fhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#751f119c-1c4e-47ab-b197-2e2d305ffa3fMartin Hatchhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20HatchUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left>Guess again .. I have done this from code.</p> <p> </p> <p align=left>My code was used below to update a ListViewWebPart.</p> <p align=left> </p> <p align=left><strong><em>NOTE - this code was used in SharePoint Products and Technologies 2003 . but the principals should be the same.</em></strong></p> <p align=left> </p> <p align=left> </p><font color="#008000" size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div><font color="#008000" size=2> <p align=left><font color="#000000">SPWeb web = SPContext.Current.web;</font></p> <p align=left><font color="#000000"></font> </p> <p align=left>// Modify title/frametype of the default.aspx web part</p></font><font size=2> <p align=left>SPWebPartCollection webParts = web.GetWebPartCollection(&quot;default.aspx&quot;, Microsoft.SharePoint.WebPartPages.Storage.Shared);</p> <p align=left> </p> <p align=left></font><font color="#0000ff" size=2>foreach</font><font size=2> (Microsoft.SharePoint.WebPartPages.WebPart webPart </font><font color="#0000ff" size=2>in</font><font size=2> webParts)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>if</font><font size=2> (webPart </font><font color="#0000ff" size=2>is</font><font size=2> Microsoft.SharePoint.WebPartPages.ListViewWebPart)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font color="#008000" size=2>// make some changes to Web Part properties</p></font> <p align=left>web</font><font size=2>Part.Title = &quot;My Custom Web Part Title&quot;;</p> <p align=left>webPart.Description = &quot;A custom description too ...&quot;;</p> <p align=left><font color="#008000" size=2>// remove the title bar</font></p> <p align=left>webPart.FrameType = Microsoft.SharePoint.WebPartPages.FrameType.TitleBarOnly;</p> <p align=left>webPart.DetailLink = &quot;default.aspx&quot;;</p> <p align=left></font><font color="#008000" size=2>// save the Web Part Changes</p></font><font size=2> <p align=left>webParts.SaveChanges(webPart.StorageKey);</p></font><font color="#0000ff" size=2> <p align=left> </p> <p align=left><font color="#008000" size=2>// Remove the Toolbar!</font></p> <p align=left><font color="#008000" size=2>// this needs to be done from the VIEW of the Web Part</p></font></font><font size=2> <p align=left>Guid webPartGuid = </font><font color="#0000ff" size=2>new</font><font size=2> Guid(((Microsoft.SharePoint.WebPartPages.ListViewWebPart)webPart).ViewGuid);</p> <p align=left>SPView webPartView = web.Lists[&quot;MyListName&quot;].Views[webPartGuid];</p> <p align=left>webPartView.Toolbar = &quot;&quot;;</p> <p align=left>webPartView.Update();</p></font></blockquote><font size=2> <p align=left>}</p></blockquote> <p align=left>}</p></font> <p align=left> </p></div></div> <p align=left> </p> <p></p></font><font size=2> <p align=left></p></font>Wed, 29 Aug 2007 16:15:26 Z2007-08-29T16:15:26Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#70438b66-0613-4a21-9d27-2ae8db7c06e8http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#70438b66-0613-4a21-9d27-2ae8db7c06e8Martin Hatchhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20HatchUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Alternatively, if the code I provided doesn't work in MOSS, try setting the &quot;Toolbar&quot; property to a blank string (&quot;&quot;) instead of &quot;none&quot;.</font></p> <p align=left> </p> <p align=left> </p>Wed, 29 Aug 2007 16:25:30 Z2007-08-29T16:25:30Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#647fd200-46d0-4368-bf85-630235860777http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#647fd200-46d0-4368-bf85-630235860777cwoglehttp://social.msdn.microsoft.com/Profile/en-US/?user=cwogleUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=3>This approach doesn't work for me in MOSS. I've tried it on document libraries, links, and custom lists. Interestingly, SPView.Toolbar is an empty string before I ever change it, and the documentation (er...what there is of it) says that it should contain CAML.</font></p> <p align=left><font size=3></font> </p> <p align=left><font size=3>I thought perhaps I should be changing SPView.ToolbarType instead. The documentation says:</font></p> <ul> <li> <p><b>Standard</b> —The most common type of toolbar, which is used, for example, in the All Items views for most lists, and which corresponds to <b>Full Toolbar</b> in the Web Part tool pane.</p> <li> <p><b>FreeForm</b> —Used in Default.aspx and Web Part Pages and corresponds to <b>Summary Toolbar</b> in the Web Part tool pane.</p> <li> <p><b>None</b> —No toolbar is used in the view, corresponding to <b>No Toolbar</b> in the Web Part tool pane.</p></li></ul><span></span> <p><font size=3>This looks exactly like what I want, but *sigh* ToolbarType is read-only.</font></p> <p align=left><font size=3></font> </p> <p align=left><font size=3>I hope the original poster will mark this thread as Not Answered so this discussion will continue. I would dearly love to change the toolbar type programmatically.</font></p> <p align=left><font size=3></font> </p> <p align=left><font size=3>fwiw, here is my code...</font></p> <p align=left> </p><font color="#008000"> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div><font color="#008000"> <p align=left>// Can't use &quot;foreach&quot; because it gives a &quot;Collection was modified&quot; error</p> <p align=left>// on the second iteration.</p></font><font color="#0000ff"> <p align=left>for</font>( <font color="#0000ff">int</font> ListNum=0; ListNum&lt;SubSite.Lists.Count; ListNum++ )</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font color="#008080">SPList</font> myList = SubSite.Lists[ListNum];</p> <p align=left><font color="#008000">// For each view in the list...</p></font> <p align=left><font color="#0000ff">foreach</font> (<font color="#008080">SPView</font> myView <font color="#0000ff">in</font> myList.Views)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font color="#008000">// If this is the default view...</p></font> <p align=left><font color="#0000ff">if</font> (myView.DefaultView)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font color="#008000">// Set view to have no toolbar.</p></font> <p align=left>myView.Toolbar = <font color="#800000">&quot;None&quot;</font>;</p> <p align=left>myView.Update();</p> <p align=left><font color="#0000ff">break</font>;</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p> <p align=left>myList.Update();</p></blockquote> <p align=left>}</p> <p align=left> </p></div></div> <p align=left> </p> <p></p></font> <p align=left></p>Wed, 29 Aug 2007 21:20:11 Z2007-08-29T21:20:11Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3030dc9f-795b-43d1-afbb-16f0dd0a933ehttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3030dc9f-795b-43d1-afbb-16f0dd0a933eviktor dolezelhttp://social.msdn.microsoft.com/Profile/en-US/?user=viktor%20dolezelUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<font face="Times New Roman"></font> <p align=left>I have the same problem. I ended up doing </p> <p align=left><font face=Courier> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div><font face=Courier>myView.Toolbar = &quot;&quot;;</font> <p align=left> </p></div></div> <p align=left> </p></font> <p></p> <p align=left>The problem now is that if you go to the web part editor and change something in this web part (anything), the toolbar will re-appear.</p>Fri, 31 Aug 2007 17:47:59 Z2007-08-31T17:47:59Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#27920ac9-e216-4f7a-bdf2-4c158e2cd6b9http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#27920ac9-e216-4f7a-bdf2-4c158e2cd6b9Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>This does not work either as you still have a standard toolbar displayed.   The direct DB update is the only way so far I was able to get it to change.  Interesting that it was updateable in SP2003.  Hopefully it is a bug that will be corrected in the coming service pack and we will not need a direct db update.</p> <p align=left> </p> <p align=left>Bruce VB</p> <p align=left> </p> <p align=left> </p> <p align=left> </p> <p align=left> </p>Tue, 04 Sep 2007 21:34:41 Z2007-09-04T21:34:41Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#a6df1e1b-5c2c-4d19-aa8d-2cfa95092ea3http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#a6df1e1b-5c2c-4d19-aa8d-2cfa95092ea3Eugen Lechnerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Eugen%20LechnerUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p>The property Toolbar setting internal xml text of Node &quot;Toolbar&quot;. This ist a bug - your need setting attribute &quot;Type&quot; of &quot;Toolbar&quot; node. Use following code:</p> <p align=left> </p><font size=2></font> <p><font color="#008080" size=2>SPView</font><font size=2> view = companyLogosLib.Views[</font><font color="#800000" size=2>&quot;Name of View&quot;</font><font size=2>];</font></p> <p><font size=2>System.Reflection.</font><font color="#008080" size=2>FieldInfo</font><font size=2> field = view.GetType().GetField(</font><font color="#800000" size=2>&quot;Node&quot;</font><font size=2>, </font><font size=2>System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.NonPublic | System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.Instance);</font></p> <p><font color="#008080" size=2>XmlNode</font><font size=2> node = field.GetValue(view) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>XmlNode</font><font size=2>;</font></p> <p><font size=2>node.SelectSingleNode(</font><font color="#800000" size=2>&quot;Toolbar&quot;</font><font size=2>).Attributes[0].Value = </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>;</font></p> <p><font size=2>view.Update();</font></p>Fri, 14 Sep 2007 08:49:26 Z2007-09-14T08:49:26Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#b099bf86-93d0-4371-ba6f-c12a5991d4c0http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#b099bf86-93d0-4371-ba6f-c12a5991d4c0Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>Cool....</p> <p align=left> Very Close but</p> <p align=left>Node is a property of SPView so you need a GetProperty instead of GetField</p> <p align=left> </p> <p><font color="#008080" size=2>SPView</font><font size=2> view = companyLogosLib.Views[</font><font color="#800000" size=2>&quot;Name of View&quot;</font><font size=2>];</font></p> <p><font size=2>System.Reflection.</font><font color="#008080" size=2><font color="#008080" size=2>PropertyInfo</font></font><font size=2> Props = view.GetType().GetProperty(</font><font color="#800000" size=2>&quot;Node&quot;</font><font size=2>, </font><font size=2>System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.NonPublic | System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.Instance);</font></p> <p><font color="#008080" size=2>XmlNode</font><font size=2> node = Props GetValue(view) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>XmlNode</font><font size=2>;</font></p> <p><font size=2>node.SelectSingleNode(</font><font color="#800000" size=2>&quot;Toolbar&quot;</font><font size=2>).Attributes[0].Value = </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>;</font></p> <p><font size=2>view.Update();</font></p> <p> </p> <p align=left>This updates the view on the list (which you cannot even do from the UI !!!) .   However if you apply the this view to the ListViewWebPart <font size=2>   <strong>lvpart.ViewGuid = view.ID.ToString(</strong></font><strong><font color="#800000" size=2>&quot;P&quot;</font><font size=2>)  </p></font></strong><font size=2> <p>you still have the tool bar on the listview on your webpart page although the base view does not.  This is because the WebPart's view is a copy of the base view's schema and not the actual view.  But  <a><strong><u><font color="#013da4">Eugen Lechner</font></u></strong></a> has led the way for us and here is the code to update ToolBar of the ListViewWebPart on a web page.</p> <p align=left> </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>lMgr =OpenWebPartManager(</font><font color="#800000" size=2>&quot;Default.Aspx&quot;</font><font size=2>); </font></p> <p align=left><font size=2></font><font color="#008000" size=2>// Get web Part</p></font><font size=2> <p>wp = lMgr.WebParts[wp.ID] </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>WebPart</font><font size=2>;</p> <p></font><font color="#008080" size=2>ListViewWebPart</font><font size=2> lv = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)wp;</p> <p></font><font color="#008000" size=2>// Extract view </p></font><font size=2> <p>System.Reflection.</font><font color="#008080" size=2>PropertyInfo</font><font size=2> ViewProp = lv.GetType().GetProperty(</font><font color="#800000" size=2>&quot;View&quot;</font><font size=2>, System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.NonPublic | System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.Instance);</p> <p></font><font color="#008080" size=2>SPView</font><font size=2> spView = ViewProp.GetValue(lv, </font><font color="#0000ff" size=2>null</font><font size=2>) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>SPView</font><font size=2>;</p> <p></font><font color="#008000" size=2>// This forces a refresh of the views internal xml or the node's cild nodes are not populated </font></p> <p align=left><font size=2></font><font color="#0000ff" size=2>string</font><font size=2> txt = spView.SchemaXml;</p> <p> </p> <p align=left>System.Reflection.</font><font color="#008080" size=2>PropertyInfo</font><font size=2> NodeProp = spView.GetType().GetProperty(</font><font color="#800000" size=2>&quot;Node&quot;</font><font size=2>, System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.NonPublic | System.Reflection.</font><font color="#008080" size=2>BindingFlags</font><font size=2>.Instance);</p> <p></font><font color="#008080" size=2>XmlNode</font><font size=2> node = NodeProp.GetValue(spView, </font><font color="#0000ff" size=2>null</font><font size=2>) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>XmlNode</font><font size=2>;</p> <p></p> <p></font><font color="#008080" size=2>XmlNode</font><font size=2> tBarNode = node.SelectSingleNode(</font><font color="#800000" size=2>&quot;Toolbar&quot;</font><font size=2>);</p> <p></font><font color="#0000ff" size=2>if</font><font size=2> (tBarNode != </font><font color="#0000ff" size=2>null</font><font size=2>)</p> <p>{</p> <blockquote dir=ltr style="margin-right:0px"> <p>tBarNode.Attributes[</font><font color="#800000" size=2>&quot;Type&quot;</font><font size=2>].Value = </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>;</p> <p>spView.Update();</p></blockquote> <p>}</p> <p> </p> <p align=left> </p></blockquote> <p dir=ltr align=left>As fun as all this Reflection and XML processing is we are still left with a hack like my direct database update from above that updates private properties that may or may not exists later.  Although better it is still unsupported by MS and could break with the next service pack.  What we need is something high tech like </p> <p dir=ltr align=left><font size=2> </p> <p>wp = lMgr.WebParts[wp.ID] </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#008080" size=2>WebPart</font><font size=2>;</p> <p></font><font color="#008080" size=2>ListViewWebPart</font><font size=2> lv = (</font><font color="#008080" size=2>ListViewWebPart</font><font size=2>)wp;</p> <p>lv.View.ToolBarType = </font><font color="#800000" size=2>&quot;None&quot;</font><font size=2>;</font></p> <p align=left><font size=2></font> </p> <p align=left>Come on MS.... Throw us a bone here....</p> <p align=left> </p> <p align=left>Regards</p> <p align=left>Bruce VB</p> <p align=left>zNetSys </p> <p align=left> </p> <p align=left> </p> <p align=left> </p> <p align=left><font size=2> </p></font></font>Tue, 18 Sep 2007 15:58:38 Z2007-09-18T16:03:45Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#35b50d38-82d9-45af-8c7c-63c81f6b582fhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#35b50d38-82d9-45af-8c7c-63c81f6b582fJacelyhttp://social.msdn.microsoft.com/Profile/en-US/?user=JacelyUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p>While still coupled pretty closely to the current CAML schema, this seems to work just fine:</p> <p align=left> </p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="color:#1f497d"><font size=3><font face=Calibri>SPView view = newSite.Lists[listID].Views[new Guid(lvwp.ViewGuid)];</font></font></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="color:#1f497d"><font size=3><font face=Calibri>view.Toolbar = &quot;&lt;Toolbar Position=\&quot;After\&quot; Type=\&quot;None\&quot; /&gt;&quot;;</font></font></span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="color:#1f497d"><font face=Calibri size=3>view.Update();</font></span></p> <p> </p> <p align=left>Alternatives could be: </p> <p> </p> <p align=left><span style="color:#1f497d"><font size=3><font face=Calibri>view.Toolbar = &quot;&lt;Toolbar Position=\&quot;After\&quot; Type=\&quot;Standard\&quot; /&gt;&quot;;</font></font></span></p> <p> </p> <p align=left>or</p> <p align=left> </p> <p align=left><span style="color:#1f497d"><font size=3><font face=Calibri>view.Toolbar = &quot;&lt;Toolbar Position=\&quot;After\&quot; Type=\&quot;Freeform\&quot;&gt;&lt;!-- CAML goes here --&gt;&lt;/Toolbar&gt;&quot;;</font></font></span></p> <p> </p> <p align=left>Jace B</p> <p align=left> </p> <p align=left>P.S. -- The reason your &quot;replace&quot; code didn't work in the first place is that the node is optional, and doesn't seems to exist by default.</p>Mon, 03 Dec 2007 19:47:39 Z2007-12-03T19:47:39Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2711cdd3-e651-4d61-b5ae-1dffc2ec686ehttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2711cdd3-e651-4d61-b5ae-1dffc2ec686ejcorrahttp://social.msdn.microsoft.com/Profile/en-US/?user=jcorraUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial></font> </p> <p>The above code doesn't work.  The problem is that the <font face=Verdana>view.Toolbar</font> property isn't the <font face=Courier>&lt;Toolbar /&gt;</font> node itself, it's the <em>content</em> of the toolbar node.  And since <font face=Verdana>Type</font> is an attribute of the toolbar node, assigning it a new value isn't possible through the <font face=Verdana>view.Toolbar</font> property.  So if your view type is already <font face=Verdana>Freeform</font>, you can use the <font face=Verdana>Toolbar</font> property to change the template, but when it's set to the default value of <font face=Verdana>Standard</font>, any content for the toolbar node seems to be completely ignored.</p> <p align=left> </p> <p align=left>However, it looks like the <font face=Verdana>SPView.HtmlSchemaXml</font> and the <font face=Verdana>ListViewWebPart.ListViewXml</font> properties are equivalent.  I tried taking the output from <font face=Verdana>view.HtmlSchemaXml</font> of the SPView that I want, replacing <font face=Courier>&lt;Toolbar Type=&quot;Standard&quot; /&gt;</font> with <font face=Courier>&lt;Toolbar Type=&quot;None&quot; /&gt;</font>, and updating that webpart in the webpart collection, but after the update the <font face=Verdana>ListViewWebPart.ListViewXml</font> is still null.  Some of the other webparts on the page do have values for <font face=Verdana>ListViewXml</font> but the one I was trying to work with remains null.  I don't know if it's because the Guid of the SPView was still in the <font face=Verdana>ListViewXml</font> that I was passing in or not, and I haven't had time to test further.</p>Wed, 09 Jan 2008 22:38:29 Z2008-01-09T22:38:29Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#ad379bf2-0fb1-428b-8b0b-87f7688b56edhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#ad379bf2-0fb1-428b-8b0b-87f7688b56edVimlahttp://social.msdn.microsoft.com/Profile/en-US/?user=VimlaUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Hi Bruce,</font></p> <p align=left>I'm creating a listviewwebpart and adding this to the webpart manager. Then trying to update my webpart view to set the toolbar type to none, the same way you described it in your post.</p> <p align=left> </p> <p align=left>However my webpart never gets updated.</p> <p align=left>Any idea.</p> <p align=left> </p> <p align=left>Appreciate your reply.</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Vimla</p>Thu, 10 Jan 2008 08:02:17 Z2008-01-10T08:02:17Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#134da8b7-b5fa-4660-9343-d2d2037ab35ahttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#134da8b7-b5fa-4660-9343-d2d2037ab35aVimlahttp://social.msdn.microsoft.com/Profile/en-US/?user=VimlaUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Hi jcorra,</font></p> <p align=left>I have the ListViewWebpart added through code that has s standard view and I've trouble changing the view as well.</p> <p align=left>You mentioned that you are using the HtmlSchemaXml, can i get some sample on this?</p> <p align=left> </p> <p align=left>Thanks</p>Thu, 10 Jan 2008 17:21:16 Z2008-01-10T17:21:16Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#f2ce08a5-3808-4f61-a0fd-4d5d7e5dc5f2http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#f2ce08a5-3808-4f61-a0fd-4d5d7e5dc5f2jcorrahttp://social.msdn.microsoft.com/Profile/en-US/?user=jcorraUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>My code samples are from a Windows Application I threw together to make testing easier (the actual application I'm working on is a custom <font color="#2b91af" size=2>SPFeatureReceiver</font> class that does site customizations when the Feature is activated, but debugging is much easier from a Windows app than from inside the SPFeature).  I have a text field where I can enter the URL of the site I want to open, a list to select the webpart to work with, a textbox that shows the HtmlSchemaXml property of the selected webpart's current view and any error messages, and a textbox for the XML string to use to update the ListViewXml property of the webpart.</p> <p align=left> </p> <p align=left>On a side note, using site.GetWebPartCollection() will generate a warning message that SPWebPartCollection has been deprecated, but I found the <font color="#008080">SPWebPartCollection</font> to be easier to work with than its replacement <font color="#008080">SPLimitedWebPartManager</font>.  I'm adding new webparts to the page in my SPFeatureReceiver, then doing additional customizations--such as trying to change the ToolBar to Type=&quot;None&quot;.  SPWebPartCollection.Add() returns the Guid of the newly added webpart, where the AddWebPart() method of the <font color="#008080">SPLimitedWebPartManager</font> is a void, so you have to do additional work to get a reference to the webpart on the page before you can do any additional work with it.</p> <p align=left> </p><font size=2> <p align=left></font><font color="#0000ff" size=2> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p align=left><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> btnConnect_Click(</font><font color="#0000ff" size=2>object</font><font size=2> sender, </font><font color="#2b91af" size=2>EventArgs</font><font size=2> e) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.Items.Clear();</p></font><font size=2> <p align=left></font><font color="#0000ff" size=2>try</font><font size=2> {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2>(</font><font color="#2b91af" size=2>SPSite</font><font size=2> site_collection = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>SPSite</font><font size=2>(</font><font color="#0000ff" size=2>this</font><font size=2>.txtSPSiteURL.Text)) {</p></font><font size=2> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2>(</font><font color="#2b91af" size=2>SPWeb</font><font size=2> site = site_collection.OpenWeb()) {</font><font size=2></p> <blockquote dir=ltr style="margin-right:0px"></font><font size=2> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.DataSource = </font><font color="#0000ff" size=2><font color="#000000">site.GetWebPartCollection(</font><font color="#a31515" size=2>&quot;Default.aspx&quot;</font><font color="#000000" size=2>, Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>Storage</font><font color="#000000" size=2>.Shared);</font></font></p> <p align=left><font size=2></font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.DisplayMember = </font><font color="#a31515" size=2>&quot;Title&quot;</font><font size=2>;</font><font size=2></p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote></font><font size=2> <p align=left>} </font><font color="#0000ff" size=2>catch</font><font size=2>(</font><font color="#2b91af" size=2>Exception</font><font size=2> ex) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.txtMessage.Text += ex.ToString();</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p> <p align=left></font><font color="#0000ff" size=2><font size=2></font></font> </p><font size=2> <p align=left></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> lstWebParts_SelectedIndexChanged(</font><font color="#0000ff" size=2>object</font><font size=2> sender, </font><font color="#2b91af" size=2>EventArgs</font><font size=2> e) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>if</font><font size=2>(</font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.Items.Count &gt; 0) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>ListViewWebPart</font><font size=2> webpart = </font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.SelectedItem </font><font color="#0000ff" size=2>as</font><font size=2> Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>ListViewWebPart</font><font size=2>;</p> <p align=left></font><font color="#0000ff" size=2>if</font><font size=2>(webpart != </font><font color="#0000ff" size=2>null</font><font size=2>) {</font></p> <blockquote dir=ltr style="margin-right:0px"><font size=2><font color="#2b91af" size=2> <p align=left>SPView</font><font size=2> view = site.Lists[</font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>Guid</font><font size=2>(webpart.ListName)].Views[</font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>Guid</font><font size=2>(webpart.ViewGuid)];</p></font></blockquote></font><font size=2> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.txtMessage.Text = <font size=2>view.HtmlSchemaXml;</p></font></blockquote> <p align=left>} </font><font color="#0000ff" size=2>else</font><font size=2> {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.txtMessage.Text = </font><font color="#0000ff" size=2>string</font><font size=2>.Format(</font><font color="#a31515" size=2>&quot;{0} is not a ListViewWebPart.&quot;</font><font size=2>, webpart.Title);</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p> <p align=left> </p><font size=2> <p align=left></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> btnUpdateSchemaXML_Click(</font><font color="#0000ff" size=2>object</font><font size=2> sender, </font><font color="#2b91af" size=2>EventArgs</font><font size=2> e) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>if</font><font size=2>(</font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.Items.Count &gt; 0) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>ListViewWebPart</font><font size=2> webpart = </font><font color="#0000ff" size=2>this</font><font size=2>.lstWebParts.SelectedItem </font><font color="#0000ff" size=2>as</font><font size=2> Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>ListViewWebPart</font><font size=2>;</p> <p align=left></font><font color="#0000ff" size=2>if</font><font size=2>(webpart != </font><font color="#0000ff" size=2>null</font><font size=2>) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2>(</font><font color="#2b91af" size=2>SPSite</font><font size=2> site_collection = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>SPSite</font><font size=2>(</font><font color="#0000ff" size=2>this</font><font size=2>.txtSPSiteURL.Text)) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2>(</font><font color="#2b91af" size=2>SPWeb</font><font size=2> site = site_collection.OpenWeb()) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>try</font><font size=2> {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#2b91af" size=2>SPWebPartCollection</font><font size=2> webparts = site.GetWebPartCollection(</font><font color="#a31515" size=2>&quot;Default.aspx&quot;</font><font size=2>, Microsoft.SharePoint.WebPartPages.</font><font color="#2b91af" size=2>Storage</font><font size=2>.Shared);</font><font size=2></p> <p align=left>webpart.ListViewXml = </font><font color="#0000ff" size=2>this</font><font size=2>.txtNewSchemaXML.Text;</p> <p align=left>webparts.SaveChanges(webpart.StorageKey);</font><font color="#008000" size=2></p></blockquote></font><font size=2> <p align=left>} </font><font color="#0000ff" size=2>catch</font><font size=2>(</font><font color="#2b91af" size=2>Exception</font><font size=2> ex) {</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#0000ff" size=2>this</font><font size=2>.txtMessage.Text = ex.ToString();</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></font></font> <p align=left> </p></div></div> <p align=left> </p></font> <p></p><font size=2><font size=2> <p align=left></p></font></font>Thu, 10 Jan 2008 19:18:34 Z2008-01-10T19:18:34Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#f27a35e1-ebad-4975-92da-dfa375224ef7http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#f27a35e1-ebad-4975-92da-dfa375224ef7Bruce VB1http://social.msdn.microsoft.com/Profile/en-US/?user=Bruce%20VB1Update ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2></font> </p> <p>If you are using the same code then it should work.   One thing you can try is to dispose of the <font size=2>LimitedWebPartManager and recreate it before you reopen the web part to set the toolbar.  </font></p> <p align=left> </p> <p align=left>Hope this helps.</p> <p align=left> </p>Thu, 10 Jan 2008 19:26:48 Z2008-01-10T19:26:48Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#11991629-65ee-4781-b0f4-460361789133http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#11991629-65ee-4781-b0f4-460361789133Vimlahttp://social.msdn.microsoft.com/Profile/en-US/?user=VimlaUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Hi jcorra,</font></p> <p align=left>Thank you for the reply.</p> <p align=left>I actually have everything that's the on the sample code.</p> <p align=left>But I would like to know how you update the view.HtmlSchemaXml through code iterating through the nodes.</p> <p align=left>Because in the sample windows application code, I guess you are manually updating it in the textbox.</p> <p align=left> </p> <p align=left>Also in my application(windows application) I'm adding a webpart and then get the view of the webpart to update the tool bar type.</p> <p align=left>How do you handle this in your custom <font color="#2b91af" size=2>SPFeatureReceiver</font> class? I guess more or less i'm doing the same in my app.</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Vimala</p> <p align=left> </p> <p align=left> </p>Thu, 10 Jan 2008 20:28:29 Z2008-01-10T20:28:29Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3a6115f8-c224-4842-ac01-78e058166acchttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3a6115f8-c224-4842-ac01-78e058166accjcorrahttp://social.msdn.microsoft.com/Profile/en-US/?user=jcorraUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p>Vimla-</p> <p align=left> </p> <p align=left>You could load the SPView.HtmlSchemaXml into an XML document if you want to manipulate it through code.  Sadly, though, it's a read-only property, so you can't update the HtmlSchemaXml of the view directly.  Same with the ToolBarType property.  The only property I've found which is both updateable and contains the &lt;Toolbar /&gt; node is the ListViewXml property of the webpart itself.</p> <p align=left> </p> <p align=left>However, so far I haven't been able to get that property to update correctly.  For an existing webpart, I tried changing just the toolbar definition to &lt;Toolbar Type=&quot;None&quot; /&gt; but when I reload the property after saving it, the ListViewXml still shows &lt;Toolbar Type=&quot;Standard&quot; /&gt;.  I thought maybe it was because there was still a Guid for the view in the Xml schema definition, and that maybe the definition of the SPView was taking precedence over the changes to the webpart's ListViewXml, so I changed my program to instead add a completely new webpart to the page with no ViewGuid defined and no Guid in the Xml schema definition.  The new webpart gets successfully added to the page, but SharePoint seems to more or less completely ignore the ListViewXml definition I gave it, because the new webpart doesn't have the same fields, any filters, and completely different ordering, none of which match any of the existing views I have on this list.  And worst of all, it was STILL added with a toolbar, but this time &lt;Toolbar Type=&quot;Freeform&quot;&gt;</p> <p align=left> </p> <p align=left>It looks like at this point, using System.Reflection or a direct database update are the only options to make this work, for something that seems like it should be simple, considering you can do it manually with 4 clicks.  I think MS needs to put a little more work into the SPView &amp; ListViewWebPart object model.  I definitely agree with Bruce, why can't there just be a ListViewWebPart.View.ToolBarType = &quot;None&quot;?  It can obviously be done somehow, since you can do it manually through the UI, so why make it readonly in the object model?</p>Thu, 10 Jan 2008 21:02:38 Z2008-01-10T21:02:38Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#0ba10c4d-37fb-408d-8217-48f1b4ffb5cehttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#0ba10c4d-37fb-408d-8217-48f1b4ffb5ceVimlahttp://social.msdn.microsoft.com/Profile/en-US/?user=VimlaUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Hi jcorra,</font></p> <p align=left>I guess Toolbar type=&quot;FreeForm&quot; works for me ...But it's just that when i add the listviewwebpart programmatically, i can't seem to modify this Standard Tool bar type at all..</p> <p align=left> </p> <p align=left>So you are adding a new webpart without setting the ViewGuid of the webpart. </p> <p align=left>So is it something like this?</p> <p align=left> </p> <p align=left>ListViewWebPart wp = <span style="color:blue">new</span> ListViewWebPart();<br>wp.ZoneID = <span style="color:maroon">&quot;Left&quot;</span>;</p> <p>wp.ListName = list.ID.ToString(<span style="color:maroon">&quot;B&quot;</span>).ToUpper();<br><span style="color:green"><br></span>SPWebPartCollection coll =  web.GetWebPartCollection(<span style="color:maroon">&quot;default.aspx&quot;</span>, Storage.Shared);</p> <p align=left> </p> <p align=left>Is there anything else that you are doing? Do you have to also set the ListViewXml through code?? How do you set the tool bar type?</p> <p align=left> </p> <p align=left>By the way I'm using the SPLimitedWebPartManager because SPWebPartCollection is Obsolete..Not sure if that makes a difference.</p> <p align=left> </p> <p align=left> </p> <p align=left>Thanks<br></p> <p align=left> </p> <p align=left> </p> <p align=left> </p>Fri, 11 Jan 2008 02:00:23 Z2008-01-11T02:00:23Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#4c7db277-5b2b-4e34-8c29-6b14ab6d8674http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#4c7db277-5b2b-4e34-8c29-6b14ab6d8674IT_Graduatehttp://social.msdn.microsoft.com/Profile/en-US/?user=IT_GraduateUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Is there a way to remve the toolbar without going through the xml?</font></p> <p align=left> </p> <p align=left>Lucy</p>Wed, 26 Mar 2008 16:14:43 Z2008-03-26T16:14:43Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#6dacfc8b-cfed-4783-931a-ea0e2f623454http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#6dacfc8b-cfed-4783-931a-ea0e2f623454jcorrahttp://social.msdn.microsoft.com/Profile/en-US/?user=jcorraUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"You only seem to be able to do it either using System.Reflection or through direct database updates, neither of which is a &quot;supported&quot; method of making customizations. <p align=left> </p>Wed, 26 Mar 2008 17:19:17 Z2008-03-26T17:19:17Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#946784e1-b2bc-4100-aa22-30a704155a9chttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#946784e1-b2bc-4100-aa22-30a704155a9cMarcel de Vrieshttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcel%20de%20VriesUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p align=left><font face=Arial size=2>Just want to let you all know I got it to work with the follwoing code:</font></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;color:blue;font-family:Consolas">private</span><b><span style="font-size:9pt;font-family:Consolas"> </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">static</span><b><span style="font-size:9pt;font-family:Consolas"> </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">void</span><b><span style="font-size:9pt;font-family:Consolas"> DisableToolbar(</span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">ListViewWebPart</span><b><span style="font-size:9pt;font-family:Consolas"> lv)</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas">{</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;color:green;font-family:Consolas"><span style=""> </span>//<span style="">  </span>Extract view </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;color:green;font-family:Consolas"> </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span>System.Reflection.</span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">PropertyInfo</span><b><span style="font-size:9pt;font-family:Consolas"> ViewProp = lv.GetType().GetProperty(</span></b><span style="font-size:9pt;color:#a31515;font-family:Consolas">&quot;View&quot;</span><b><span style="font-size:9pt;font-family:Consolas">, <br><span style="">    </span>System.Reflection.</span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">BindingFlags</span><span style="font-size:9pt;font-family:Consolas">.NonPublic | System.Reflection.<span style="color:#2b91af">BindingFlags</span>.Instance);</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;font-family:Consolas"> </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span></span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">SPView</span><b><span style="font-size:9pt;font-family:Consolas"> spView = ViewProp.GetValue(lv, </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">null</span><b><span style="font-size:9pt;font-family:Consolas">) </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">as</span><b><span style="font-size:9pt;font-family:Consolas"> </span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">SPView</span><b><span style="font-size:9pt;font-family:Consolas">;</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;font-family:Consolas"> </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span></span></b><span style="font-size:9pt;color:blue;font-family:Consolas">string</span><b><span style="font-size:9pt;font-family:Consolas"> txt = spView.SchemaXml;</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span>System.Reflection.</span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">PropertyInfo</span><b><span style="font-size:9pt;font-family:Consolas"> NodeProp = spView.GetType().GetProperty(</span></b><span style="font-size:9pt;color:#a31515;font-family:Consolas">&quot;Node&quot;</span><b><span style="font-size:9pt;font-family:Consolas">, <br><span style="">     </span>System.Reflection.</span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">BindingFlags</span><span style="font-size:9pt;font-family:Consolas">.NonPublic | System.Reflection.<span style="color:#2b91af">BindingFlags</span>.Instance);</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;font-family:Consolas"> </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">  </span><span style=""> </span></span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">XmlNode</span><b><span style="font-size:9pt;font-family:Consolas"> node = NodeProp.GetValue(spView, </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">null</span><b><span style="font-size:9pt;font-family:Consolas">) </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">as</span><b><span style="font-size:9pt;font-family:Consolas"> </span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">XmlNode</span><b><span style="font-size:9pt;font-family:Consolas">;</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span></span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">XmlNode</span><b><span style="font-size:9pt;font-family:Consolas"> tBarNode = node.SelectSingleNode(</span></b><span style="font-size:9pt;color:#a31515;font-family:Consolas">&quot;Toolbar&quot;</span><b><span style="font-size:9pt;font-family:Consolas">);</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;font-family:Consolas"> </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span></span></b><span style="font-size:9pt;color:blue;font-family:Consolas">if</span><b><span style="font-size:9pt;font-family:Consolas"> (tBarNode != </span></b><span style="font-size:9pt;color:blue;font-family:Consolas">null</span><b><span style="font-size:9pt;font-family:Consolas">)</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">   </span>{</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span></span></b><span style="font-size:9pt;color:#2b91af;font-family:Consolas">XmlAttribute</span><b><span style="font-size:9pt;font-family:Consolas"> typeNode = tBarNode.Attributes[</span></b><span style="font-size:9pt;color:#a31515;font-family:Consolas">&quot;Type&quot;</span><b><span style="font-size:9pt;font-family:Consolas">];</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span></span></b><span style="font-size:9pt;color:green;font-family:Consolas">// make the contents empty so we realy remove the toolbar .....</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;color:green;font-family:Consolas"><span style="">      </span>// otherwise you might get a different type of toolbar popup when we have a <br><span style="">      </span>// Migrated site from 2.0</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span>tBarNode.RemoveAll();</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span></span></b><span style="font-size:9pt;color:green;font-family:Consolas">// re-add the type attribute</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span>tBarNode.Attributes.Append(typeNode);</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">      </span></span></b><span style="font-size:9pt;color:green;font-family:Consolas">// finally set the toolbar to not show....</span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">       </span>typeNode.Value = </span></b><span style="font-size:9pt;color:#a31515;font-family:Consolas">&quot;None&quot;</span><b><span style="font-size:9pt;font-family:Consolas">;</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style="">    </span>}</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><span style="font-size:9pt;color:green;font-family:Consolas">//This forces a refresh of the views internal xml or the node's cild nodes are not populated </span></p> <p class=MsoNormal style="background:#d9d9d9;margin:0in 0in 0pt;line-height:normal"><b><span style="font-size:9pt;font-family:Consolas"><span style=""> </span>spView.Update();<br>}</span></b><span style="font-size:9pt;font-family:Consolas"></span></p> <p>Thanks for all the pointers in this thread. I just tought to post the final solution I got working.</p> <p align=left>Cheers,</p> <p align=left>Marcel</p>Thu, 10 Apr 2008 18:39:09 Z2008-04-10T18:39:09Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#45fd74dc-5782-4fbc-ab29-f12a48a69aabhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#45fd74dc-5782-4fbc-ab29-f12a48a69aabFrank-Ovehttp://social.msdn.microsoft.com/Profile/en-US/?user=Frank-OveUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"Thank you, Marcel.<br><br>Worked like a charm! :)<br><br>Frank<br> Sat, 06 Sep 2008 15:19:54 Z2008-09-06T15:19:54Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#fbec6ceb-be45-42eb-be21-4c99527e041ahttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#fbec6ceb-be45-42eb-be21-4c99527e041ajasear [MCTS SharePoint]http://social.msdn.microsoft.com/Profile/en-US/?user=jasear%20%5bMCTS%20SharePoint%5dUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" This only seems to work to set the toolbar to none. If I try to set it to Freeform, although in the Web Part Page when I click on properties it does show Summary Toolbar as the selected toolbar but the view I get of the toolbar is that of none. When I click apply then it is ok.<hr size="1" align="left" width="25%">jasearMon, 06 Oct 2008 11:48:56 Z2008-10-06T11:48:56Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#78bc8ed6-e21a-4314-bf8a-e1bf2243c3bahttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#78bc8ed6-e21a-4314-bf8a-e1bf2243c3baAvinashKThttp://social.msdn.microsoft.com/Profile/en-US/?user=AvinashKTUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"  <p>We can achieve same thing by setting following property:</p> <p>webPart.SuppressWebPartChrome = true;<br><br>~ Avinash</p>Thu, 13 Nov 2008 06:24:47 Z2008-11-13T06:24:47Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#6091ee64-5e13-479b-b0be-eed14176e356http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#6091ee64-5e13-479b-b0be-eed14176e356linghuzijianhttp://social.msdn.microsoft.com/Profile/en-US/?user=linghuzijianUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" OH!!SO GOOD! ThanksTue, 18 Nov 2008 05:41:32 Z2008-11-18T05:41:32Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#5ce5b310-4488-4d2f-9b47-b73790f7fccehttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#5ce5b310-4488-4d2f-9b47-b73790f7fcceAvinashKThttp://social.msdn.microsoft.com/Profile/en-US/?user=AvinashKTUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Hi,<br><br>One of the problem with following code :<br><br>listViewWebPart.SuppressWebPartChrome = true;<br><br>is that it hide the toolBar in ListViewWebPart as well as in the SPList/SPView from which it is displaying the data <br>( I face this problem, not sure about others :) ).<br><br>So, the other alternative is to add following CSS in our code:<br><br><font color="#0000ff" size=2> <p>&lt;</font><font color="#a31515" size=2>style</font> <font color="#ff0000" size=2>type</font><font color="#0000ff" size=2>=&quot;text/css&quot;&gt;<br></font><font color="#a31515" size=2>    .ms-menutoolbar</font><font size=2>    { </font><font color="#ff0000" size=2>display</font><font size=2>: </font><font color="#0000ff" size=2>none</font><font size=2>; }<br></font><font color="#0000ff" size=2>&lt;/</font><font color="#a31515" size=2>style</font><font color="#0000ff" size=2>&gt;</p></font>Be careful while using the above CSS, because it hide all the ToolBars which uses the  <font size=2><font color="#a31515">.ms-menutoolbar</font>    CSS class.<br><br>~ Avinash</font>Tue, 25 Nov 2008 05:17:56 Z2008-11-25T05:17:56Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#9fb351ce-4c6c-4854-9295-16cbae86a032http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#9fb351ce-4c6c-4854-9295-16cbae86a032jasear [MCTS SharePoint]http://social.msdn.microsoft.com/Profile/en-US/?user=jasear%20%5bMCTS%20SharePoint%5dUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Has anyone had any luck with this yet? We have spent almost 1 month trying to find a solution to this problem. We have written a migration tool that imports ListViewWebParts (amongst other things) from SP2003 to MOSS 2007. We are able to add the ListViewWebParts and setup almost all the properties but we are unable to programmatically set the toolbartype. <br><br>Why the SPView.ToolBarType property was made readonly I dont know because if it wasnt it would have been as simple as:<br><br>SPViewToolBarType = &quot;Freeform&quot;;<br><br>We tried the solution suggested in here which partially worked for us until we installed some latest updates after which that completely stopped working.<br><br>Can someone please help us with this? <hr class="sig">jasearFri, 05 Dec 2008 11:02:07 Z2008-12-05T11:02:07Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#35984a6f-7be1-4f34-9112-f3461b531160http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#35984a6f-7be1-4f34-9112-f3461b531160jasear [MCTS SharePoint]http://social.msdn.microsoft.com/Profile/en-US/?user=jasear%20%5bMCTS%20SharePoint%5dUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Perhaps we could reverse engineer this? When we go to a sharepoint page and do this on the UI it gets updated correctly. Anyone have any ideas how it is done then? Can someone give me some tips on how I can reverse engineer this?<hr class="sig">jasearWed, 17 Dec 2008 10:12:41 Z2008-12-17T10:12:41Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#bf65c958-80ba-46cc-a6e5-78da55fbd910http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#bf65c958-80ba-46cc-a6e5-78da55fbd910AvinashKThttp://social.msdn.microsoft.com/Profile/en-US/?user=AvinashKTUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Hi Jasear,<br><br>I am not sure, but you can directly change the <strong>ListViewXml </strong>programmatically to modify the ToolBarType. <br>In my case I modified the empty message thats ListView WebPart displays when it contains no record/SPListItem.<br>You can check the code sample at <a href="http://avinashkt.blogspot.com/2008/12/sharepoints-listviewwebpart.html">SharePoint's ListViewWebPart</a>.<br><br>In your case, first check the whole XML and then modified the desired node. Use following code to check the <b>ListViewXml :<br></b>Response.Write(oListViewWP.ListViewXml);<br><br>~ Avinash Wed, 17 Dec 2008 10:44:28 Z2008-12-17T10:44:28Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#5ff648c2-9912-4ddf-bf0f-cccf97f71508http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#5ff648c2-9912-4ddf-bf0f-cccf97f71508FrodeMhttp://social.msdn.microsoft.com/Profile/en-US/?user=FrodeMUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Hi,<br><br>I have had this same problem, and have been following this thread as I've been trying to resolve it. Finally found a solution for this at Tippu's blog(Mubarak Musthafa). This works excellent, and can be used on almost any kind of list. This code sample removes the toolbar and sets it to use the &quot;Summary view&quot;. It can easily be modified to just remove the toolbar.<br><br><a href="http://tippu.blog.co.in/2008/10/08/how-to-set-a-listviewwebparts-toolbar-type-as-summary-web-part/">Tippu’s Blog</a><br><br>Wrote this to give you a complete sample using Tippu's code to set the toolbar.<br><br>Sample code using an announcement list:<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px"></font><font style="color:green">//Get a reference to the current SPWeb. </font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">SPWeb newWeb = SPContext.Current.Web;  </td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7"></font><font style="color:green">//Create an instance of an announcement list. </font><font style="font-size:11px"> </font></td></tr> <tr> <td>SPListTemplateType listtemplatetype = SPListTemplateType.Announcements;  </td></tr> <tr> <td style="background-color:#f7f7f7">Guid listID = newWeb.Lists.Add(</font><font style="color:blue">&quot;Announcements&quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;&quot;</font><font style="font-size:11px">, listtemplatetype);  </font></td></tr> <tr> <td>SPList newsList = newWeb.Lists[listID];  </td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td></font><font style="color:green">//Get a reference to the SPFile object associated with the default.aspx, using an  </font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7"></font><font style="color:green">//SPLimitedWebPartManager object to add the webpart. </font><font style="font-size:11px"> </font></td></tr> <tr> <td>SPLimitedWebPartManager webPartManager;  </td></tr> <tr> <td style="background-color:#f7f7f7">SPFile page = newWeb.Files[</font><font style="color:blue">&quot;default.aspx&quot;</font><font style="font-size:11px">];  </font></td></tr> <tr> <td>webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);  <br></td></tr> <tr> <td style="background-color:#f7f7f7"></font><font style="color:green">//Create and add a ListViewWebPart. </font><font style="font-size:11px"> </font></td></tr> <tr> <td>ListViewWebPart lwp = </font><font style="color:blue">new</font><font style="font-size:11px"> ListViewWebPart();  </font></td></tr> <tr> <td style="background-color:#f7f7f7">lwp.Title = </font><font style="color:blue">&quot;Announcements&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>lwp.ListName = newsList.ID.ToString(</font><font style="color:blue">&quot;B&quot;</font><font style="font-size:11px">).ToUpper();  </font></td></tr> <tr> <td style="background-color:#f7f7f7">webPartManager.AddWebPart(lwp, </font><font style="color:blue">&quot;Left&quot;</font><font style="font-size:11px">, 0);  </font></td></tr> <tr> <td>newWeb.Update();  </td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td></font><font style="color:green">//Extract the view  </font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">PropertyInfo ViewProp = lvWebPart.GetType().GetProperty(</font><font style="color:blue">&quot;View&quot;</font><font style="font-size:11px">, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);  </font></td></tr> <tr> <td>SPView spView = ViewProp.GetValue(lvWebPart, </font><font style="color:blue">null</font><font style="font-size:11px">) </font><font style="color:blue">as</font><font style="font-size:11px"> SPView;  </font></td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td></font><font style="color:green">//Remove the toolbar and set it to use the &quot;summary view&quot;. </font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">SetWebPartToolbarAttribute(spView, </font><font style="color:blue">&quot;Freeform&quot;</font><font style="font-size:11px">); </font></td></tr></tbody></table></div><br>Tippu's code:<br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px"></font><font style="color:blue">private</font><font style="font-size:11px"> </font><font style="color:blue">static</font><font style="font-size:11px"> </font><font style="color:blue">void</font><font style="font-size:11px"> SetWebPartToolbarAttribute(SPView spView, String AttributeValue)  </font></td></tr> <tr> <td style="background-color:#f7f7f7">{  </td></tr> <tr> <td>    </font><font style="color:blue">string</font><font style="font-size:11px"> txt = spView.SchemaXml;  </font></td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td>    System.Reflection.PropertyInfo NodeProp = spView.GetType().GetProperty(</font><font style="color:blue">&quot;Node&quot;</font><font style="font-size:11px">, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);  </font></td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td>    XmlNode node = NodeProp.GetValue(spView, </font><font style="color:blue">null</font><font style="font-size:11px">) </font><font style="color:blue">as</font><font style="font-size:11px"> XmlNode;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">    XmlNode tBarNode = node.SelectSingleNode(</font><font style="color:blue">&quot;Toolbar&quot;</font><font style="font-size:11px">);  </font></td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">if</font><font style="font-size:11px"> (tBarNode != </font><font style="color:blue">null</font><font style="font-size:11px">)  </font></td></tr> <tr> <td>    {  </td></tr> <tr> <td style="background-color:#f7f7f7">        XmlAttribute typeNode = tBarNode.Attributes[</font><font style="color:blue">&quot;Type&quot;</font><font style="font-size:11px">];  </font></td></tr> <tr> <td>        tBarNode.RemoveAll();  </td></tr> <tr> <td style="background-color:#f7f7f7">        tBarNode.Attributes.Append(typeNode);  </td></tr> <tr> <td>        typeNode.Value = AttributeValue;  </td></tr> <tr> <td style="background-color:#f7f7f7">    }  </td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">if</font><font style="font-size:11px"> (String.Compare(AttributeValue, </font><font style="color:blue">&quot;Freeform&quot;</font><font style="font-size:11px">, </font><font style="color:blue">true</font><font style="font-size:11px">) == 0)  </font></td></tr> <tr> <td>    {  </td></tr> <tr> <td style="background-color:#f7f7f7">        </font><font style="color:blue">string</font><font style="font-size:11px"> NewItemString = </font><font style="color:blue">&quot;&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>        XmlAttribute pos = tBarNode.OwnerDocument.CreateAttribute(</font><font style="color:blue">&quot;Position&quot;</font><font style="font-size:11px">);  </font></td></tr> <tr> <td style="background-color:#f7f7f7">        pos.Value = pos.Value = </font><font style="color:blue">&quot;After&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>        tBarNode.Attributes.Append(pos);  </td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td>        </font><font style="color:blue">switch</font><font style="font-size:11px"> (spView.ParentList.BaseTemplate)  </font></td></tr> <tr> <td style="background-color:#f7f7f7">        {  </td></tr> <tr> <td>             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.Announcements:  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             NewItemString = </font><font style="color:blue">&quot;announcement&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.DiscussionBoard:  </font></td></tr> <tr> <td>             NewItemString = </font><font style="color:blue">&quot;discussion&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.Links:  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             NewItemString = </font><font style="color:blue">&quot;link&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.Tasks:  </font></td></tr> <tr> <td>             NewItemString = </font><font style="color:blue">&quot;task&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.GenericList:  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             NewItemString = </font><font style="color:blue">&quot;element&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">case</font><font style="font-size:11px"> SPListTemplateType.DocumentLibrary:  </font></td></tr> <tr> <td>             NewItemString = </font><font style="color:blue">&quot;document&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">             </font><font style="color:blue">break</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>        }  </td></tr> <tr> <td style="background-color:#f7f7f7">        tBarNode.InnerXml = @</font><font style="color:blue">&quot;&lt;IfHasRights&gt;&lt;RightsChoices&gt;&lt;RightsGroup PermAddListItems=&quot;</font><font style="font-size:11px">&quot;required&quot;</font><font style="color:blue">&quot; /&gt;&lt;/RightsChoices&gt;&lt;Then&gt;&lt;HTML&gt;&lt;![CDATA[ &lt;table width=100% cellpadding=0 cellspacing=0 border=0 &gt; &lt;tr&gt; &lt;td colspan=&quot;</font><font style="font-size:11px">&quot;2&quot;</font><font style="color:blue">&quot; class=&quot;</font><font style="font-size:11px">&quot;ms-partline&quot;</font><font style="color:blue">&quot;&gt;&lt;IMG src=&quot;</font><font style="font-size:11px">&quot;/_layouts/images/blank.gif&quot;</font><font style="color:blue">&quot; width=1 height=1 alt=&quot;</font><font style="font-size:11px">&quot;&quot;</font><font style="color:blue">&quot;&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class=&quot;</font><font style="font-size:11px">&quot;ms-addnew&quot;</font><font style="color:blue">&quot; style=&quot;</font><font style="font-size:11px">&quot;padding-bottom: 3px&quot;</font><font style="color:blue">&quot;&gt; &lt;img src=&quot;</font><font style="font-size:11px">&quot;/_layouts/images/rect.gif&quot;</font><font style="color:blue">&quot; alt=&quot;</font><font style="font-size:11px">&quot;&quot;</font><font style="color:blue">&quot;&gt;&amp;nbsp;&lt;a class=&quot;</font><font style="font-size:11px">&quot;ms-addnew&quot;</font><font style="color:blue">&quot; ID=&quot;</font><font style="font-size:11px">&quot;idAddNewItem&quot;</font><font style="color:blue">&quot; href=&quot;</font><font style="font-size:11px">&quot;]]&gt;&lt;/HTML&gt;&lt;URL Cmd=&quot;</font><font style="color:blue">&quot;New&quot;</font><font style="font-size:11px">&quot; /&gt;&lt;HTML&gt;&lt;![CDATA[&quot;</font><font style="color:blue">&quot; ONCLICK=&quot;</font><font style="font-size:11px">&quot;javascript:NewItem(']]&gt;&lt;/HTML&gt;&lt;URL Cmd=&quot;</font><font style="color:blue">&quot;New&quot;</font><font style="font-size:11px">&quot; /&gt;&lt;HTML&gt;&lt;![CDATA[', </font><font style="color:blue">true</font><font style="font-size:11px">);javascript:</font><font style="color:blue">return</font><font style="font-size:11px"> </font><font style="color:blue">false</font><font style="font-size:11px">;&quot;</font><font style="color:blue">&quot; target=&quot;</font><font style="font-size:11px">&quot;_self&quot;</font><font style="color:blue">&quot;&gt;]]&gt;&lt;/HTML&gt;&lt;HTML&gt;Add a new &quot;</font><font style="font-size:11px"> + NewItemString + @</font><font style="color:blue">&quot;&lt;/HTML&gt;&lt;HTML&gt;&lt;![CDATA[&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;IMG src=&quot;</font><font style="font-size:11px">&quot;/_layouts/images/blank.gif&quot;</font><font style="color:blue">&quot; width=1 height=5 alt=&quot;</font><font style="font-size:11px">&quot;&quot;</font><font style="color:blue">&quot;&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;]]&gt;&lt;/HTML&gt;&lt;/Then&gt;&lt;/IfHasRights&gt;&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>    }  </td></tr> <tr> <td style="background-color:#f7f7f7">    spView.Update();  </td></tr> <tr> <td>}</td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr></tbody></table></div><br>This does the trick for me. Hope this can be of help to others too.<br><br>~FrodeMMon, 22 Dec 2008 13:25:53 Z2008-12-22T13:47:15Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2d18655a-fdff-4502-b4d4-91b69c6f73c8http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2d18655a-fdff-4502-b4d4-91b69c6f73c8jasear [MCTS SharePoint]http://social.msdn.microsoft.com/Profile/en-US/?user=jasear%20%5bMCTS%20SharePoint%5dUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" The solutions mentioned in this thread will not work once you install the latest infrastructure update which is what happened to us. However thanks to Ton Stegeman and Brian Farhill there is a solution here:<br><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5-28d9-464f-b1c9-91e07c8f7e47&amp;ID=90">http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5%2D28d9%2D464f%2Db1c9%2D91e07c8f7e47&amp;ID=90</a><br><br>Basically, you need to replace:<br><br>string txt = view.ScehamaXml; <br><br>with:<br><br>                webpartView.GetType().InvokeMember(<span style="color:#006080">&quot;EnsureFullBlownXmlDocument&quot;</span>, <br>                    BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,<br>                    <span style="color:#0000ff">null</span>, webpartView, <span style="color:#0000ff">null</span>);<br><br>That is the toolbartype sorted. If you want to be able to set the view then you need to make sure that you set the view first and then call the addwebpart method. If the webpart is already on the page then you need to delete it and then set the properties of your listviewwebpart including the viewguid and then add the web part. Unfortunately, I havent been able to find any other way of setting the view.<hr class="sig">jasearTue, 06 Jan 2009 09:58:12 Z2009-01-06T09:58:12Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#81dbece1-c5d0-4fa4-a61f-4b200a0df5d2http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#81dbece1-c5d0-4fa4-a61f-4b200a0df5d2Avaneethttp://social.msdn.microsoft.com/Profile/en-US/?user=AvaneetUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" Hi,<br>You will definetly achieve it. <br>Some approaches are discussed in the following post:<br><br><a href="http://etechplanet.com/post/2009/02/05/AddingRemoving-toolbar-from-custom-ListViewWebPart.aspx">http://etechplanet.com/post/2009/02/05/AddingRemoving-toolbar-from-custom-ListViewWebPart.aspx</a><br><br>Regards,<br>AvaneetThu, 12 Feb 2009 15:13:30 Z2009-02-12T15:13:30Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#ea624a4c-08bd-46b9-bda3-13c56a78f7aahttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#ea624a4c-08bd-46b9-bda3-13c56a78f7aaC Buchananhttp://social.msdn.microsoft.com/Profile/en-US/?user=C%20BuchananUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None" I've posted a solution to updating the ListViewWebPart Toolbar type at:<br><br><a href="http://spschris.blogspot.com/2009/02/updating-toolbar-type-for-sharepoint.html">http://spschris.blogspot.com/2009/02/updating-toolbar-type-for-sharepoint.html</a><br><br>Hope this helps resolve this issue.<br><br>Chris Buchanan<br>Solution Developer<br><a href="http://www.redsphere.ca">www.redsphere.ca</a><hr class="sig">ChrisFri, 20 Feb 2009 22:53:59 Z2009-02-20T22:53:59Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#98b98564-227f-433e-b76e-3791d3cc2b7ahttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#98b98564-227f-433e-b76e-3791d3cc2b7ajasear [MCTS SharePoint]http://social.msdn.microsoft.com/Profile/en-US/?user=jasear%20%5bMCTS%20SharePoint%5dUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"As I have already mentioned. That solution will not work if you have installed the latest infrasructure update.<br/><br/>The following solution works:<br/><br/><a href="http://jasear.wordpress.com/2009/04/05/listviewwebpart-programatically-setting-the-toolbartype-property/">http://jasear.wordpress.com/2009/04/05/listviewwebpart-programatically-setting-the-toolbartype-property/</a><hr class="sig">Visit my blog http://jasear.wordpress.comSun, 05 Apr 2009 19:23:49 Z2009-04-05T19:23:49Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#acbc85e8-a8ce-4c1a-90f5-f3536fe0a035http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#acbc85e8-a8ce-4c1a-90f5-f3536fe0a035Narayana Reddy GundReddyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Narayana%20Reddy%20GundReddyUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"Hi all,<br/><br/> I want to share following code which removes tool bar for list view webpart<br/> I did it based on the inputs provided by you all.<br/> Thank you all.<br/><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">  </span></span><span style="color:blue">protected</span><span style="color:#000000"> </span><span style="color:blue">override</span><span style="color:#000000"> </span><span style="color:blue">void</span><span style="color:#000000"><span style="">  </span>CreateChildControls()</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span><span style=""> </span>{</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:#2b91af">SPSite</span><span style="color:#000000"> site = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">SPSite</span><span style="color:#000000">(</span><span style="color:#2b91af">SPContext</span><span style="color:#000000">.Current.Site.Url.ToString());</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:#2b91af">SPWeb</span><span style="color:#000000"> web = site.OpenWeb();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">       </span>web.AllowUnsafeUpdates = </span><span style="color:blue">true</span><span style="color:#000000">;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:#2b91af">SPList</span><span style="color:#000000"> list = web.Lists[</span><span style="color:#a31515">&quot;Name of the List&quot;</span><span style="color:#000000">];</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span><span style="">      </span></span><span style="color:#2b91af">ListViewWebPart</span><span style="color:#000000"> lvwp = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">ListViewWebPart</span><span style="color:#000000">();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">       </span>lvwp.ListName = list.ID.ToString(</span><span style="color:#a31515">&quot;B&quot;</span><span style="color:#000000">).ToUpper();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:#2b91af">SPView</span><span style="color:#000000"> view = list.Views[</span><span style="color:#a31515">&quot;Name of the View&quot;</span><span style="color:#000000">];</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">       </span>System.Reflection.</span><span style="color:#2b91af">PropertyInfo</span><span style="color:#000000"> Props = view.GetType().GetProperty(</span><span style="color:#a31515">&quot;Node&quot;</span><span style="color:#000000">, System.Reflection.</span><span style="color:#2b91af">BindingFlags</span><span style="color:#000000">.NonPublic | System.Reflection.</span><span style="color:#2b91af">BindingFlags</span><span style="color:#000000">.Instance);</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:#2b91af">XmlNode</span><span style="color:#000000"> node=Props.GetValue(view,</span><span style="color:blue">null</span><span style="color:#000000">) </span><span style="color:blue">as</span><span style="color:#000000"> </span><span style="color:#2b91af">XmlNode</span><span style="color:#000000">;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">                    </span><span style="">                           </span>node.SelectSingleNode(</span><span style="color:#a31515">&quot;Toolbar&quot;</span><span style="color:#000000">).Attributes[0].Value=</span><span style="color:#a31515">&quot;None&quot;</span><span style="color:#000000">;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">     </span><span style="">  </span>view.Update();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">       </span>lvwp.ViewGuid = view.ID.ToString(</span><span style="color:#a31515">&quot;B&quot;</span><span style="color:#000000">).ToUpper();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span>lvwp.ViewType = </span><span style="color:#2b91af">ViewType</span><span style="color:#000000">.Html; </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span>lvwp.GetDesignTimeHtml();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:blue">this</span><span style="color:#000000">.Controls.Add(lvwp);</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">       </span></span><span style="color:blue">base</span><span style="color:#000000">.CreateChildControls();</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">  </span>}</span></span></p> <font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p> </p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p> </p>Fri, 19 Jun 2009 13:30:27 Z2009-06-19T13:30:27Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3d9a4b54-19b4-4229-a422-1e82b25363b5http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#3d9a4b54-19b4-4229-a422-1e82b25363b5Mark Stokeshttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20StokesUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"The problem I am having with this is that the Toolbar child node doesn't exist.<br/> <br/> I am creating a new SPView on the list, then setting the ListViewWebPart to that view, then I delete it.  but this new view doesn't have a Toolbar child node, and when I try to add it, the ListViewWebPart drops back to use the default View and not my custom view.<br/> <br/> I have tried using the DefaultView as well and removing the ToolBar... but as far as I can see, none of the views are returning a Toolbar child node.<br/> <br/> Any ideas?<br/> <br/> Mark StokesWed, 01 Jul 2009 09:55:04 Z2009-07-01T09:55:04Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#e3d128e5-2794-4b54-93d8-43708e7b6b34http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#e3d128e5-2794-4b54-93d8-43708e7b6b34Mark Stokeshttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20StokesUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"OK,<br/> <br/> I finally got my head around this and have created a blog article about it:<br/> <a title="http://sharepointstudio.com/People/MarkStokes/Lists/Posts/Post.aspx?ID=27" href="http://sharepointstudio.com/People/MarkStokes/Lists/Posts/Post.aspx?ID=27" title="http://sharepointstudio.com/People/MarkStokes/Lists/Posts/Post.aspx?ID=27">http://sharepointstudio.com/People/MarkStokes/Lists/Posts/Post.aspx?ID=27</a> <br/> <br/> Hope this helps<br/> <br/> Mark Stokes<br/> <a title="http://sharepointstudio.com" href="http://sharepointstudio.com" title="http://sharepointstudio.com">http://sharepointstudio.com/</a> <br/>Thu, 02 Jul 2009 10:04:50 Z2009-07-02T10:04:50Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#9d83f068-3990-41e1-84d8-4ebb497eef0bhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#9d83f068-3990-41e1-84d8-4ebb497eef0bShobha Phttp://social.msdn.microsoft.com/Profile/en-US/?user=Shobha%20PUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"Hi Mark Stokes,<br/><br/>I tried ur code for removing the toolbar. when i set the toolbar property to 'None'. In listviewwebpart, in place of toolbar it shows text 'None'. Have you also faced the issue?Thu, 02 Jul 2009 11:59:36 Z2009-07-02T11:59:36Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2b7c8833-7a99-46d6-a6cf-aabd2e41e2a6http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#2b7c8833-7a99-46d6-a6cf-aabd2e41e2a6Mark Stokeshttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20StokesUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"I have not seen this happen in my environment.<br/> <br/> Are you able to post your code here and I will have a look at it.<br/> <br/> Mark<br/> <br/>Thu, 02 Jul 2009 13:07:34 Z2009-07-02T13:07:34Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#551df4ba-f8d8-4c3b-ad76-4922f6920fcbhttp://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/96aac2dd-29fc-4e63-8730-9d1adc01b826#551df4ba-f8d8-4c3b-ad76-4922f6920fcbMohamed Hachemhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mohamed%20HachemUpdate ListViewWebPart to Remove or Hide Toolbar ToolbarType="None"<p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">Hello <br/><br/><br/> Franks and Bruce VB1 solutions are working</span></p> <p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">I want to mention what is happening <span style=""> </span>in order to clarify both solutions. </span></p> <p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">Actually, List view webpart should be added first to the page. What we normally see and by default is the current view not the one we create. <br/><br/>Therefore to change the view ex: either remove toolbar or header, w</span><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">e have to use reflection on the actual webpart to get the current view and then modify it.</span></p> <p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'"><span style=""> </span>to remove header 1) use reflection, 2) spView.ViewHeader = string.Empty; </span></p> <p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">to remove toolbar please follow <span style=""> </span>the provided solution by those two guys I mentioned above.</span></p> <p class=MsoNormal style="margin:0cm 0cm 10pt"><span style="font-size:8pt;color:black;line-height:115%;font-family:'Verdana','sans-serif'">Cheers</span></p> <p>Note: Please be aware that if the user go and edit the current view toolbar will show up, as added<br/>         to the list view web part.</p><hr class="sig">MomoTue, 03 Nov 2009 01:23:50 Z2009-11-03T01:23:50Z