SharePoint Dragons

Nikander & Margriet on SharePoint

Monthly Archives: May 2012

Missing SharePoint 2010 Project Templates

What to do when you can’t find the SharePoint 2010 project templates in Visual Studio.NET 2010? This link http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/a1f7631b-d901-430c-9777-ab67747678d3/ discusses what you can do.

The SharePoint Flavored Weblog Reader v1.1

In a previous post, we’ve talked about a tool we’ve created, the SharePoint Flavored WebLog Reader: https://sharepointdragons.com/2012/02/17/the-sharepoint-flavored-weblog-readersfwr/. It’s a free tool that analyzes the IIS logs of SharePoint farms and generates several textual reports about them. We’ve just released an update to it (v1.1) and based on community feedback, two new features were incorporated:

  • An overview was added that displays the number of searches executed per user.
  • An overview was added of the top slowest requests for a specific user.

You can get it here: http://gallery.technet.microsoft.com/The-SharePoint-Flavored-5b03f323

Web.config modifications

This is a nice blog post that explains how to make web.config modificatons via a SharePoint feature: http://smartrider.wordpress.com/2011/03/03/how-to-add-and-remove-entries-from-web-config-using-spwebconfigmodification/

Estimating and Benchmarking SharePoint projects

Potentially, this is the most interesting and exciting Wiki page we’ve ever worked on: http://social.technet.microsoft.com/wiki/contents/articles/10590.sharepoint-2010-best-practices-estimating-and-benchmarking-project-efforts.aspx On the other hand, it may well turn out to be a waste of our time. We’ll let you decide, we’ve taken the first steps. We very much want to encourage you to read it, appreciate it, contribute to it, or ignore it (hah, just when you thought you didn’t fit in any of the groups we went in for the kill!). Depending on what happens, it can become something quite special or we’ll just have to let go. We realize it can be near impossible (and admittedly, utterly useless) to give an ultimatum to a community, but we guess we just did!

Martin Luther putting 95 theses on the door of a church.

The JavaScript client OM

Developing solutions in the JavaScript client object model can be tedious and error prone. As a preferred way, it’s easier to start building a project using the managed client object model as it supports IntelliSense and debugging. When you’re finished, you can then port that version to the JavaScript OM. Alternatively, you can get some IntelliSense support for JavaScript by including the following line in an application page/site page/visual web part:

<% #if DEBUG %>
<script type=”text/javascript” src=”/_layouts/MicrosoftAjax.js” ></script> <script type=”text/javascript” src=”/_layouts/SP.debug.js”></script>
<% #endif %>

This is described in more detail here: http://sharepointinfoit.wordpress.com/2011/12/29/how-to-enable-ecma-client-object-model-intellisense-in-visual-studio-2010/

<% #if DEBUG %>
<script type=”text/javascript” src=”/_layouts/MicrosoftAjax.js” ></script> <script type=”text/javascript” src=”/_layouts/SP.debug.js”></script>
<% #endif %>

In, for example, a visual web part, the JavaScript OM js files have already been imported for you, so the following code is to wet your appetite and it updates a status field for a specific set of list items:

<script type=”text/javascript”>
    function onSucceeded(sender, args) {

        var itemEnum = listItems.getEnumerator();
        while (itemEnum.moveNext()) {
            var item = itemEnum.get_current();
            //alert(item.get_item(“Title”) + ” status:” + item.get_item(“MyStatus”) + ” : id ” + item.get_id());
                item.set_item(‘MyStatus’, ‘my new value’);
                item.update();
                context.load(item);

            }
        }

        context.executeQueryAsync(onSucceededStatusUpdate, onFailed);
    }
    function onSucceededStatusUpdate(sender, args) {
        alert(“status updated”);
    }

    var context;
    var web;
    var list;

    var listItems;
    var listItem;

    function InitClientOmContext() {
        context = new SP.ClientContext.get_current();
        web = context.get_web();
        list = web.get_lists().getByTitle(“MyPrintList”);
        listItem = list.getItemById(1);
    }

    function UpdateStatus(arrItems) {
        try {
            InitClientOmContext();

            // Note: Make sure that all fields are indeed part of the content type.
            // Dynamically create CAML query:
            var caml = “<View><ViewFields><FieldRef Name=’Id’/><FieldRef Name=’Title’/><FieldRef Name=’MyStatus’/></ViewFields><Query><Where><In><FieldRef Name=’ID’/><Values>”;

// arrItems is not included, but is a JavaScript array containing id’s
            for (i in arrItems) {
                caml += “<Value Type=’Number’>” + arrItems[i] + “</Value>”
            }
            caml += “</Values></In></Where></Query></View>”;
            //alert(caml);
            //var caml = “<View><Query><Where><Eq><FieldRef Name=’ID’/><Value Type=’Number’>2</Value></Eq></Where></Query></View>”;
            //var caml = “<View><ViewFields><FieldRef Name=’Title’/></ViewFields><RowLimit>5</RowLimit></View>”;
            //(<Where><FieldRef Name=”ID”/><Value>xx</Value></Where>)
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml(caml);
            listItems = list.getItems(camlQuery);

            context.load(web);
            context.load(list);
            context.load(listItems);
            context.load(listItem, ‘Title’);
            context.executeQueryAsync(onSucceeded, onFailed);
        }
        catch (err) {
            alert(“error in update status ” + err.Message);
        }
    }

    function onFailed(sender, args) {
        alert(“fail: ” + args.get_message() + “\n” + args.get_stackTrace());
    }

</script>

Auditing in SharePoint Foundation?

Yes, you can, though it’s not supported via the GUI, see http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/53e79142-88c9-48f1-b5a5-a6259c9f6f97 for details:

. Go to Start -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell

2. When it is loaded you then run the following command to get your site collection object:

$site = Get-SPSite http://site_URL

3. If you don’t get errors then execute the following commands one by one to set audit options and update it:

$site.Audit.AuditFlags = [Microsoft.SharePoint.SPAuditMaskType]::Update

$site.Audit.Update()

4. [Microsoft.SharePoint.SPAuditMaskType]::Update is a enum value of type SPAuditMaskType. You can have a look here for all possible values: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spauditmasktype.aspx

If you want to combine them then use -bxor in your script. Example for Delete and Update:

[Microsoft.SharePoint.SPAuditMaskType]::Update -bxor [Microsoft.SharePoint.SPAuditMaskType]::Delete

The GUI also doesn’t offer the option to show the audit logs, so you need to do that like so:

$site.Audit.GetEntries()

Or check out the audit log enabler at http://auditlogsp.codeplex.com/ which apparently needs to be enhanced, like so (because it by default shows the results to all site members):

<CustomAction
Id=”ItemAuditing.ECBItemMenu”
RegistrationType=”ContentType”
RegistrationId=”0x01″
ImageUrl=”/_layouts/images/GORTL.GIF”
Location=”EditControlBlock”
Sequence=”300″
Title=”View Audit History”
Rights=”AddListItems”>
<UrlAction Url=”~site/_layouts/AuditingLog/ItemAudit.aspx?ItemId={ItemId}&amp;ListId={ListId}”/>
</CustomAction>

Tipsy

Let’s start our day with a nice little tip about a jQuery plugin called Tipsy: http://onehackoranother.com/projects/jquery/tipsy/ , it provides Facebook-like tooltips effects and is quite nice.

TechNet Wiki

SharePoint 2010 Best Practices

There are at least three kinds of best practices. Often, when companies inform about best practices they actually mean: what does MS say is the best practice. It’s also possible that people are referring to what are in fact practices, but not necessarily the best ones. And then there are true best practices.

The following Wiki page: http://social.technet.microsoft.com/wiki/contents/articles/8666.sharepoint-2010-best-practices-en.aspx contains a considerable list of SharePoint 2010 Best Practices. They are not best practices of the first kind we’ve mentioned (as they are not officially dictated and endorsed by MS), so we’ll leave it to you to decide if they are of the 2nd or 3rd kind. Or, heck, you can even contribute if you like!

AD group or SharePoint group?

Should you use an AD group or a SharePoint group as the basis of your SharePoint farm security infrastructure: http://social.technet.microsoft.com/wiki/contents/articles/10550.sharepoint-2010-best-practices-ad-groups-or-sharepoint-groups.aspx