This is a quick post on writing a custom ListViewByQuery WebPart on a designated SharePoint 2010 site. By using a ListViewByQuery Control, developers can easily create a default looking ListView Webpart with added bespoke functionality as they have the luxury of rendering desired caml query to pull data out from an existing list. Perhaps the biggest advantage is that you can present ListViewByQuery WebPart on a different site especially when you want to work within the confines of your SharePoint permission security layer.
I have deployed the ListViewByQuery WebPart inside a custom webpart. I would recommend you to use Visual Studio 2010 – Empty SharePoint Project (then) – Add New Item – Web Part (Template) for this solution. This will give you all the mapped folders and files etc so nothing for you to worry about. Open your UserControl.ascx File and add the following.
<SharePoint:ListViewByQuery runat="server" id="LVWP" />
Now open the UserControl.ascx.vb file and add the following.
LVWP.List = SPContext.Current.Web.Lists("Some List") Dim caml As SPQuery = New SPQuery(LVWP.List.DefaultView) caml.Query = "<caml>Desired CAML Syntax</caml>" LVWP.Query = caml
This is it, now your ListViewByQuery WebPart is ready to be used on the page. For full access to its properties and methods follow the link.
I have found ListViewByQuery WebPart known for not having:
a) SharePoint 2010 Ribbon being activated when you click on the List Item.
b) No Access to DataSheet View.
c) No ‘Add New Item’ option either.
Needless to say, it is a good reporting tool. Please continue on Google Trails or MSDN SharePoint 2010 Development & Programming Forum if you want to further investigate the above.