Archive

Archive for May, 2011

Opening A Web Part Page In Maintenance View

May 29th, 2011 Abed Khooli No comments

The title of this post may look odd, especially if you haven’t been through one of those situations when you start editing a web part page (adding or editing a web part) and suddenly, you get an error message and can no longer go back to the page to fix the problem. This could also be true if a user edited a personal view and ruined the page.
Take another scenario: you closed some web parts on a page (as opposed to deleting them) and you can no longer remember what you did but also notice that the page is a little slow. You can edit the page and see hidden web parts, but closed ones are not visible (unless you edit the page and try to insert a web part and you see an additional group called Closed web parts or use SharePoint Designer which will display closed web parts as gray blocks). In any case, the trick we are looking at today is simple: attached the string ?contents=1 to the url of the page (http://site-address/page.aspx?contents=1). You will be soon redirected to a url of this format: http://site-address/_layouts/spcontnt.aspx?url=path-to-page-encoded and the page will list available web parts in both public and personal views (public is default and can switch to personal from the top links). The list includes title, type and whether the web part is open on the page or not (no = closed). You can delete offending web parts or close ones (for testing, otherwise delete).
To delete a closed web part, you can add it (from closed web parts) and then delete it from the page.
You can delete all closed web parts using script – here’s a blog post on how to do so.

Categories: Web Parts Tags: closed web parts, maintenance view

Code Snippets In SharePoint Designer 2010

May 25th, 2011 Abed Khooli No comments

Code snippets are pre-defined blocks of code (or html source if you so prefer). You can use a snippet to enter a short block quickly and easily – just as you do in Visual Studio, for example.
In SharePoint Designer, while in source mode (the code view), press CTRL+ENTER and you will see a list of possible snippets together with a link to customize the list. The link is handy as the snippets themselves are not easy to find: from File, go to Options – to get the SharePoint Designer options dialog. From General, select Page Editor Options and then select the Code Snippets tab. You can see the available ones with their content, add new, modify existing or remove.
While at this screen, it is worth inspecting all the available options and settings on otehr tabs and other configurations like application options, ribbon and quick access toolbar.
For the current site open in Designer, there is also a site options link specific to current site (the Site tab on the ribbon).

Categories: SharePoint Designer 2010 Tags: code snippets

Displaying List Items From One Site Into Another Site

May 24th, 2011 Abed Khooli 17 comments

SharePoint Designer 2010 allows you to save a list view (which is simply a web part) as a webpart either in the top site gallery or as a file. You can then insert the web part into a parent or sub site to view the original (and any updates to) list items at the other site. This works between parent and sub site or the other way round. However, there seems to be an issue with saving the web part to the gallery directly. Instead, use the Save To File option.
Open the site where the original list is located in SharePoint Designer 2010, navigate to the list and select a view to export. Open the view and select the xsltview web part. From List View Tools, select the web part tab. Then, select To File (from save web part group). Type a name for the file (leave the extension as is) and answer Yes to the dialog that follows (do you want to show list data …).
Now, from your site collection’s site settings, select Galleries – Web parts. Click Documents from the ribbon’s Library Tools and upload the file you have just saved. Select a title and a group for your web part (so you’ll find it easily later). Now, in the other site, on a web part page (or any web part zone on a page), add a web part and select your group then your web part.
Saving to gallery directly seems to miss the Web ID (GUID) in the web part xml source (the element ) which references where the original list lives. You can edit the web part and fix it, of course, but easier to just save to file.
Note: if adding the web part from the browser results in an “unexpected error” and you are asked to open the page in maintenance mode, do so and try to add the web part from SharePoint Designer 2010. This was the case with a tasks list and may also apply to lists with workflows.

Categories: Lists, SharePoint Designer 2010, Views, Web Parts Tags: save web part, Show list data in another site

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).

Categories: Data Form, SharePoint Designer 2010 Tags: Date Difference

Using Web Services To Display Lists and Views

May 21st, 2011 Abed Khooli No comments

In the previous post, I talked about hidden lists and views and how you can use a web service to surface a number of list and view properties. In this post, I will outline the actual steps involved.
First, we will define two data sources in SharePoint Designer 2010 based on the SOAP Service connection: open the specific site in SPD, from the site objects navigation, select Data Sources. From the ribbon tab (data sources) select SOAP service connection. Provide a name on the General tab of the dialog and an optional description (we will call it Lists) and leave the Login tab as is. In the sources, enter http://site-address/_vti_bin/Lists.asmx?WSDL
Click the Connect button and select the GetListCollection item from the Operations drop down. Click OK to close the dialog.
Create a web part page and insert a data view based on the Lists source (Insert – Data View and find Lists under the SOAP Services category). We need to do this now as we will need to get a list id to initialize the second data source. Make sure the Name column is displayed (use add/remove columns if needed) and copy one of the names (including the curly brackets). Keep this for the next step.
Next, create another SOAP source and call it Views with address: http://site-address/_vti_bin/Views.asmx?WSDL and in the Operation drop down, select GetViewCollection. You’ll notice that it requires a parameter called ListName. Highlight the row and click Modify. Paste the Name you copied earlier in the default value box and check the box “the value of this parameter ..). Click OK twice to save the Views source.
Back on the web part page, add another data view based on the Views SOAP source. You should see one or more views belonging to the list you selected. Now, we need to connect the two web parts.
Select the Views web part and click Add Connection (from the ribbon) and select Get Parameters From on the first screen and click Next. Click Next on teh second screen and also on the third one (should have Lists and Send Row Data to). In the next screen, you are asked to match a field from the Lists web part to the ListName parameter. The item on the left reads “none”. Click it to select Name from the drop down and click Next. Keep Title as the hyperlink and check Indicate Current Selection Using, from the options (click modify) select ID from key columns. Click Next then Finish. Save your page and test it. Once you click a list title, its views are displayed and the title becomes bold. You can add/remove columns from either the Lists and Views dataform web parts and also control column order. Be sure to hide or block this page from unauthorized users. Notice that, unlike a REST service, a SOAP service can see the external list but it won’t report its item count (it shows 0). Although asmx services are on their way to retire, they can still be handy for several scenarios.

Categories: Lists, SharePoint Designer 2010, Views, Web Parts, Web Services Tags: DataForm,