Archive

Archive for September, 2011

How To Get A List Of Active Users In SharePoint 2010

September 30th, 2011 Abed Khooli No comments

A few days ago, a question was asked on one of the SharePoint forums. The thread owner wanted to e-mail all active users in the farm to inform them of an upcoming system reboot. In a reply, I thought about using our good old friend – the IIS log. IIS logs per web application and since a farm does not have many, it is possible to track down the relevant places to look into. But how do you define active users? The short answer is you can’t.
However, for practical purposes, you can define a time window or interval and say something like “users who have made a request in the last few minutes are most likely ‘online’ right now”. You define your time interval and zoom in to extract the users (IIS records the logged in user in cs-username column in the logs). But IIS logs, usually stored on daily basis, have so many lines and you need a tool to analyze them.
The Log Parser 2.2 (dates back to 2005) is a great tool and works well with IIS 7.5 and Windows 2008. You will be amazed by what this 1.5 MB installer can achieve. There is a help file and some sample queries in the install folder and you can see online help in this IIS blog and the log parser forums. Log Parser is a command line tool but it uses standard SQL syntax for its queries (there is a beta GUI on codeplex called Visual Log Parser).
So, I downloaded the installer, installed it and picked the current log file for my web application (you can find this from IIS under logging). The query is rather simple:
LogParser “SELECT distinct cs-username INTO test.log  FROM C:\inetpub\logs\LogFiles\W3SVC1498786109\u_ex110930.log where time > ’14:30:00′ and time < ’14:40:00′ ” -o:csv
The above line launches Log Parser, provides a select statement and defines the output format (-o:csv or comma separated format) and the file to write to (test.log or better test.csv if you want to open with Excel). My time window is 10 minutes from 2:30 pm (not a busy server, just a test VM).  As you can see, the processing is fast and an earlier time window had 3 users active.
Of course, you could count the current users in the query, but to send them e-mail you have to make some further work (map to e-mails and send the message or use some automated process that takes csv log ins as input).
The power of Log Parser should not be underestimated. You can create charts and get other reports and statistics. You can map the logs folder to a local or network drive and run Log Parser from a client machine. I just wanted to illustrate the active users as a proof of concept in the SharePoint context.

Categories: SharePoint Server 2010 Tags: Active Users, Log Parser

All Checked Out Documents Via Site Content And Structure

September 23rd, 2011 Abed Khooli 1 comment

The Site Contents and Structure (under Site Actions – Manage Content and Structure) is a very handy management and reporting tool at the site collection level scope. It allows you to view and drill down through site contents including subsites and you can create new sites, pages and lists as well as manage existing items (copy, move, delete) and also change settings. Out of the box, you also get a few reports and where possible, you can view related resources (ex. images that belong to a certain page).
In addition to the default (all documents), you can view My Tasks, Items Checked out to Me, Last Modified by Me, Pending Approval, Drafts, Going Live in 7 Days and Expiring in 7 Days. These are all great, but what if you need other custom reports? For example, you need all checked out documents (for any user). The answer is relatively simple. SharePoint stores report definitions (including criteria) in a SharePoint list called Content and Structure Reports (http://site-collection-root-url/Reports%20List/). The criteria uses the CAML query language. So, to add a custom report, you add an item to the list and specify your CAML criteria.
In this example, you can examine the criteria for checked out to me and adjust it. Instead of specifying current user, we look for same fields that are not null:

Once you save the item and refresh content and structure, your new report will show in the drop down and the results will come out with no code (except CAML criteria).
You can, of course, write code to get the same result or customize the CQWP to get custom views, but the above method is simple and effective. Next time you log to your SharePoint site, try to make use of Content and Structure and feel free to add some custom reports.

Categories: SharePoint Server 2010 Tags: All Checked Out Documents, CAML Query, Site Content and Structure

Use InfoPath Form For New and Edit But Not For Display Item

September 19th, 2011 Abed Khooli No comments

InfoPath forms, where applicable and available, are a great way to improve the look and feel of your list forms and also for adding client side functionality like validation and rules. InfoPath forms disable the default SharePoint forms for new, edit and display item on a content type basis (ex. the Item content type, which is the basis of many lists). This default behavior is not desired in some cases and the ability to modify the display form (or at least use the default SharePoint version) is needed. One good example is a list that has a lookup to another list: the OOB behavior of the display form is to hyperlink the lookup value to its details form. In InfoPath form (all purpose form), this is not the case – you see the lookup like plain text. The fix is easy.
Open the list in SharePoint Designer. On the details page, in the Content Types section (lower left of the details pane), click Item (or the content type you are using). A new page opens with the content type settings. All you need to do is modify the Display Form (under Forms). Instead of ~list/item/displayifs.aspx (Item is the content type in this case), use ~list/dispform.aspx (or whichever display form you want to use). Save your changes (top left) and that’s it.

Categories: Forms, InfoPath 2010 Tags: InfoPath display form

How To Disable Caching In CQWP

September 17th, 2011 Abed Khooli 1 comment

The Content Query Web Part is very useful for content aggregation and roll-up across the site collection scope. It was around in the previous version of SharePoint but has been improved in 2010 as can be seen in this MSDN Blog. There are, however, some inconveniences associated with it. CQWP may have issues with anonymous access as described here. The other issue which was discussed in this thread and also mentioned (2007) in this post is related to caching.
So, you configure a CQWP and apply some filtering. You test the results and they look OK. Then, you discover that new additions or updates are not reflected instantly – not even with a forced refresh, unless you try several times. You may go back to edit the web part and find that results are reflected immediately after an edit, but that’s not a solution.
The problem is related to caching which cannot be adjusted from the user interface. There are two workarounds: either export the web part and add a property to the exported file and re-import it (as explained in the thread above) or edit the page hosting the CQWP in SharePoint Designer to add a property to the tag directly: edit the page and while the CQWP is selected, switch to code view and add
UseCache=”False”
to the

Categories: CQWP Tags:

Setting The Default Value Of A DateTime Column

September 3rd, 2011 Abed Khooli 2 comments

This is a very brief post that addresses the calculated default value of a SharePoint 2010 column. There is a difference between a calculated column (you set the column type to: Calculated (calculation based on other columns)) and a calculated default value (additional column settings: default value). In the latter case, you can use volatile tokens like Today or Me – since they are used only once to initialize the column value. Volatile values should not be used for calculated columns.
So, if we have a column whose type is DateTime and we do need to keep both date and time, and also need to initialize it with current date (including time), the interface will not be very helpful. You can set the default value to Today’s Date but that will not get the time accurately.  It turns out that the Calculated Value option accepts the familiar Now() function. So, just select calculated value and type = NOW() as the formula. In a new form, the date and time controls will be filled automatically with current date and time (to the nearest minute).
If you have access to InfoPath and the list can be customized, you can easily set the default value for the date control (it will also use the Now() function).
Notice that the default value (or whatever is saved in the column) does not change (automatically) if you edit the item later (as opposed to using volatile functions in a calculated column).

Categories: Lists Tags: calculated default value,