Archive

Archive for the ‘Data Form’ Category

List Of All Lists In A Web Using ListOfLists DataSourceMode

June 8th, 2011 Abed Khooli No comments

I wrote earlier about using a SOAP service to get an inventory of lists within a certain site. This post uses a different approach and can also be filtered for a particular type of list. So, if you need to view all task lists or calendars or document libraries or surveys or even external lists based on the __spBaseTemplate property.
The approach is fairly simple. Create a web part page in the relevant site and insert an empty data view (insert – data view – empty data view). You will get a link to select a datasource and you can select any list (in this example, the Links list was selected – random selection). You have a few fields selected in the data source details pane to the right, so you just select the “Insert selected fields as …” and choose Multiple Item View from the drop down (this is in the data source details pane near the top, select view/data source from the ribbon if the datasource is not visible). You should see some rows if the selected list is not empty.
Now, switch to code view (bottom left of the status bar) and locate the <SharePoint:SPDataSource runat=”server” DataSourceMode=”List” fragment of the code and change List to ListOfLists and switch back to design view.
You may notice something strange: a grid with several rows and no data inside. That’s ok. We’ll fix soon. While the dataform web part is selected, go to Add/Remove columns from the ribbon (data view tools – options tab). Remove the select fields (right side) and select a few of those starting with 2 underscores (__). Enlarge the image of the example to get a few to start with (I did not rename them for illustration, you should). In the Paging option (next to add/remove columns), select Display all items. That should give you a list of all lists (libraries included) within the site.
if you want just a specific type of list, click Filter (ribbon options) and then from the filter dialog, check add XSLT filtering and click Edit to add your filter. For example, use [@__spBaseTemplate='ExternalList'] to get only external lists.
You can adjust to dataform view, link lists or conditional format as you need, including the title of the web part which is named after your selected list by default. Notice that this works within one site (by default, the site you created the page in).

How To Display Documents From Different Libraries Using DataView

June 4th, 2011 Abed Khooli 8 comments

The content query webpart (CQWP) is usually used for content rollup across a site collection and it is very powerful, but it is not easy to customize and style. Using a dataform webpart with some tweaking can do the trick (and you have to use SharePoint Designer 2010 to do that).
A blog article titled SPDataSource and Rollups with the Data View is the starting point here. You basically edit the data source in source mode to enable cross list fetching of items and specify what kind of list you want to include. Lists (and libraries) have something called ServerTemplate id or value and you can find these here. A document library has value = 101.
So, here’s how we start: add a web part page and insert an empty data view (insert – data view – empty data view). Click to add source and select a document library. In this case, I selected Shared Documents in a team site (and I also have a blank site under it with another document library called blankdocs). Then, inserted the datasource selected fields as multiple item view. I added a filter (from options) to include items with title that contains the word “Policy” and also selected which fields to show and items per page (all items).
Now, switch to source mode and find the datasource tag (if you had the view selected, you get the corresponding source highlighted). You need to change DataSourceMode=”List”  to DataSourceMode=”CrossList” and in the selectcommand add &lt;Webs Scope=&quot;Recursive&quot;&gt;&lt;/Webs&gt;&lt;Lists ServerTemplate=&quot;101&quot;&gt;&lt;/Lists&gt; inside the <view></view> tags. Notice that the < and > are replaced with their own literals. This should get the items, but how do you link to the documents themselves? Well, select one of the titles, right-click and select Format as .. hyperlink. Keep the Text To Display as is and in the address, put {concat(‘/’,substring-after(@FileRef,’#'))} and you are done. You can clean up other fields or format them differently or even do conditional formatting. Documents come from any library in the site collection meeting the criteria. You cold do the same for other types of lists (remember to use the correct ServerTemplate value and adjust links.

SPDataSource and Rollups with the Data View

Calculating the Age Of Your List Items In SharePoint 2010

May 23rd, 2011 Abed Khooli 7 comments

Well, why would you do that? That was actually a question on the SharePoint forums and it boils down to calculating date differences which is not well supported as one may think. Calculating the number of days from a certain date till the current date can be useful – you may want to determine the birthdays or how old a person is if their date of birth is in a list or even just flagging items that have been added or updated in the past n days.
There are some tricks working around using [Today] in calculated columns (which is not allowed), but these may not work or require other steps to keep [Today] current (like updating all list items to trigger it to change).
The answer is in the XSL. In fact, since dataforms support adding a formula as a column, I will use that feature.
Create a web part page and add a data form to it (insert Data View / Empty Data View). Select your list or library as the source and select a few fields from the source and choose to insert selected fields as Multiple Item view. Choose Add/Remove columns to customize the list and add a Formula column to the list (last item). You will be prompted to construct the formula. Here, we count the number of days since a list item was created and here’s the formula:
((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),7,2)) + floor((153 * ((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2)) + 12 * (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12)) – 3) + 2) div 5) + ((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) * 365 + floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 4) – floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 100) + floor(((substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(ddwrt:TodayIso()), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 400) – 32045) – ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),7,2)) + floor((153 * ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2)) + 12 * (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12)) – 3) + 2) div 5) + ((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) * 365 + floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 4) – floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 100) + floor(((substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),0,5)) + 4800 – (floor((14 – (substring(ddwrt:FormatDateTime(string(@Created), 1033, ‘yyyyMMdd’),5,2))) div 12))) div 400) – 32045)
This is actually based on the great work from a blog by Mark Kruger (the xsl way is more user friendly to read, of course). The formula subtracts the creation date from today’s date and involves converting dates to Julian. Once you close the formula, it will have an ugly header which you can replace with your own.
Note: make sure you use regular single and double quotes if you copy the formula and end up with tidy quotes (those with curly end).