tag:blogger.com,1999:blog-8257012011174718720.post1170441751392256098..comments2024-03-28T00:35:17.905-07:00Comments on Stefan Stanev's SharePoint blog: ListViewWebPart – set the toolbar with code without reflectionStefan Stanevhttp://www.blogger.com/profile/08627530356349625319noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-8257012011174718720.post-71683342343457766312011-09-14T13:40:08.284-07:002011-09-14T13:40:08.284-07:00Hi Krisna,
I am not sure if you need just a regula...Hi Krisna,<br />I am not sure if you need just a regular type of view or some other special type, thus I am not sure whether you need some very basic stuff which can be found in MSDN like - http://msdn.microsoft.com/en-us/library/ff728096.aspx or you need something more advanced. Another good hint that I can think of is to check the schema.xml files of the standard list definition features. For instance you can check the schema.xml of the standard document library feature located in /14/TEMPLATE/features/DocumentLibrary/DocLib. You can see for example the definition of the "all items" view in it - it is the "View" element whose "BaseViewID" attribute equals to 1. The view definition is very concise and easy to follow. Let me know if this is of help for you.Stefan Stanevhttps://www.blogger.com/profile/08627530356349625319noreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-7318154102795258452011-09-13T08:37:10.124-07:002011-09-13T08:37:10.124-07:00Hi Stefan
I want to create a list definition in Vi...Hi Stefan<br />I want to create a list definition in Visual Studio 2010 for SharePoint 2010. I have achieved it by seleting ListDefinition item, and stucked in creating a View definition. Can you suggest me how to define a view in the list definition...the requirement is for document library. I want to create a view called "Summary View".Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-67799435326015206812011-08-25T11:15:36.812-07:002011-08-25T11:15:36.812-07:00Hi Wie,
I was terribly wrong with the suggestion t...Hi Wie,<br />I was terribly wrong with the suggestion that you can provide a modified version of a base view schema which will be applied to the LVP. Actually by providing a view schema to the ListViewXml property you only specify the BaseViewID of a view definition from the list's schema and that's it. All other modifications to the original view schema will be simply ignored. So this may solve generally the problem with the toolbar (since normally the view definition with BaseViewID=0 comes with no toolbar) but will be virtually useless for other sorts of customizations that are not present in the standard view definitions in the schema.xml of the SharePoint list. I created a small solution for the issue that you have, but unfortunately it resorts to reflection. You can find the sample code here: https://sites.google.com/site/stefanstanev/sharepoint-samples-1/Program.cs?attredirects=0&d=1<br />I will also update the posting accordingly.Stefan Stanevhttps://www.blogger.com/profile/08627530356349625319noreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-77022246733620382432011-08-22T16:23:56.620-07:002011-08-22T16:23:56.620-07:00Did you end up helping the problem that the Anonym...Did you end up helping the problem that the Anonymous poster from 3/2/2011? <br />I'm having the same problem. Even though I set the lvwp.ListViewXml to something else, once the page is checked in, the ListViewWebPart reverts back to the default view.wiehttps://www.blogger.com/profile/18063529525833009071noreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-8851266616482104452011-03-02T05:09:49.683-08:002011-03-02T05:09:49.683-08:00Hi,
you can escape the > and < with &gt;...Hi,<br />you can escape the > and < with &gt; and &lt; or send the CAML to code@stefan-stanev.com.Stefan Stanevhttps://www.blogger.com/profile/08627530356349625319noreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-29382974126805215572011-03-02T05:05:06.914-08:002011-03-02T05:05:06.914-08:00The comments field of your Blog refuses to accept ...The comments field of your Blog refuses to accept my CAML code. Any suggestions?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-86761128271321481902011-03-01T12:22:05.979-08:002011-03-01T12:22:05.979-08:00Hi Anonymous,
can you show me (post) the line in t...Hi Anonymous,<br />can you show me (post) the line in the view schema XML that you change, so that I can try to reproduce your steps.Stefan Stanevhttps://www.blogger.com/profile/08627530356349625319noreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-87343808681663177302011-03-01T06:03:28.776-08:002011-03-01T06:03:28.776-08:00I'm trying to accomplish what you are describi...I'm trying to accomplish what you are describing above. My steps:<br /><br />1. Retrieve the existing "Comments" ListView WebPart from a "blog/list/posts/post.aspx" page (sucess)<br />2. Get the CAML view schema from the Blog "Comments" list via GetUncustomizedViewByBaseViewId(0).HtmlSchemaXml; (success)<br />3. Change a single line of the schema XML via a simple string replace (success)<br />4. Now I am creating a new LV WebPart (success)<br />5. Put all the same properties from the original LV WebPart on the newly created one (sucess)<br />6. Set the new schema XML on the newly created LV WebPart via .ListViewXml property (success)<br />7. Add the newly created LV WebPart to the page and hide the original one (success)<br /><br />While all steps succeed, the changed schema XML does not take effect. While the new XML is put into the .ListViewXml successfully (and it can be retrieved afterwards) it is simply gone once the page is reloaded and the newly added LV WebPart .ListViewXml is retrieved.<br /><br />I verified that my schema XML change is correct by temporarily modifying the schema.xml of the Blog "Comments" list. After an iisreset the built-in Blog "Comments" LV WebPart shows my changes, so the CAML appears to be valid. However, it is not an option to modify built-in files or rollout a custom Blog site definition just for this one-line CAML tweak (plus it should work farm-wide on all existing Blogs).<br /><br />Here is my code (simplified a little bit):<br /><br /> SPWeb currentWeb = SPControl.GetContextWeb(Context);<br /> SPList blogCommentsList = currentWeb.GetList("/lists/comments/allcomments.aspx");<br /> string = blogCommentsListId = "{" + blogCommentsList.ID.ToString().ToUpper() + "}";<br /> currentWeb.AllowUnsafeUpdates = true;<br /> using (SPLimitedWebPartManager webPartManagerLimited = currentWeb.GetLimitedWebPartManager("http://server/blog/posts/post.aspx", PersonalizationScope.Shared))<br /> {<br /> SPLimitedWebPartCollection webPartCollection = webPartManagerLimited.WebParts;<br /> foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in webPartCollection)<br /> {<br /> if (typeof(Microsoft.SharePoint.WebPartPages.ListViewWebPart) == webPart.GetType())<br /> {<br /> // After reloading the page lvWebPart.ListViewXml is back to the original<br /> ListViewWebPart lvWebPart = (ListViewWebPart)webPart;<br /> if (lvWebPart.ListName == blogCommentsListId && !webPart.Title.Contains("Enhanced - "))<br /> {<br /> string schemaXml = blogCommentsList.GetUncustomizedViewByBaseViewId(0).HtmlSchemaXml;<br /> string newViewXml = schemaXml.Replace("oldHTML", "newHTML");<br /><br /> ListViewWebPart newLvWebPart = new ListViewWebPart();<br /> newLvWebPart.Title = "Enhanced - " + lvWebPart.Title;<br /> newLvWebPart.ListName = blogCommentsListId;<br /> newLvWebPart.ChromeState = lvWebPart.ChromeState;<br /> newLvWebPart.ChromeType = lvWebPart.ChromeType;<br /> newLvWebPart.AllowClose = lvWebPart.AllowClose;<br /> newLvWebPart.AllowConnect = lvWebPart.AllowConnect;<br /> newLvWebPart.AllowEdit = lvWebPart.AllowEdit;<br /> newLvWebPart.AllowHide = lvWebPart.AllowHide;<br /> newLvWebPart.AllowMinimize = lvWebPart.AllowMinimize;<br /> newLvWebPart.AllowRemove = lvWebPart.AllowRemove;<br /> newLvWebPart.AllowZoneChange = lvWebPart.AllowZoneChange;<br /> newLvWebPart.ListViewXml = newViewXml;<br /> // At this point newLvWebPart.ListViewXml contains the new CAML!!!<br /> webPartManagerLimited.AddWebPart(newLvWebPart, lvWebPart.ZoneID, lvWebPart.ZoneIndex);<br /> newLvWebPart.ListViewXml = newViewXml;<br /> webPartManagerLimited.SaveChanges(newLvWebPart);<br /> break;<br /> }<br /> }<br /> }<br /> }<br /> currentWeb.AllowUnsafeUpdates = false;<br /><br /><br />Any pointer is much appreciated!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8257012011174718720.post-38882200587610781522010-11-09T04:20:37.866-08:002010-11-09T04:20:37.866-08:00Hi Stefan,
This is an excellent post! Exactly the...Hi Stefan,<br /><br />This is an excellent post! Exactly the same that I was looking for. I had problems in adding a new LV web part with a desired (hidden) view that was available in the list schema.xml. <br />Thanks a lot and please keep up the good work!Anonymousnoreply@blogger.com