SharePoint Dragons

Nikander & Margriet on SharePoint

Monthly Archives: May 2012

Best Practices for Service Accounts

We like the following post about best practices for service accounts: http://seclists.org/basics/2008/Sep/225 Although this is not limited to SharePoint, we tend to see the world to SharePoint glasses and apply it to the SharePoint world.

Copying or moving a thicket file

We remember, a long time ago, when we were working on a chapter for an MS Press Administrator Companion book, we were reading one of the other chapters and it mentioned a thicket file. We re-read it, baffled, and the sentence still said thicket file. We later found it that this is a pretty common reaction to thicket files. We looked it up and found out a thicket is an Office doc saved as a web page. Every time you save a file as HTML that contains contains resources that can’t be stored within HTML (such as images) these get stored in a special linked folder called [file name]_files.

When you save a thicket in a SharePoint library, the special linked folder gets hidden. Also, SharePoint “protects” this type of folder by preventing you from creating folders that end with either _file or _files. In such cases, it appends an underscore (_) and renames the folder name to either _file_ or _files_:

image

Another thing to note about the combination of thicket file/SharePoint is that it’s not easy to copy or move them. Renaming or deleting the html file won’t affect the special linked folder and if you use the object model to rename it (using the MoveTo() method) you’ll get an error message saying you can’t copy or move a thicket file. A work-around exists and it’s described here: http://sharemypoint.wordpress.com/2007/07/24/_files-folder-part-2-you-cannot-copy-or-move-a-thicket-file-how-to-rename/

Keep your focus – Kyteman

Someone once gave us the advice that every blog should have a focus point. In our case, that’s easy, our main focus point is and remains SharePoint. Most of our posts are directly related to this topic. The second part of the advice was that you can do off-topic blog posts up to a maximum of 20%. And that, if you choose to do an off-topic post, you should choose it well.

Well, here it is. Our first off-topic post. It’s completely unrelated to SharePoint, instead it’s related to music. Kyteman is a young Dutch musician, and there are times when we think he just might be brilliant. Or, as http://kyteman.com/#about puts it, Kyteman was born with an unusual gift for music. Our non-Dutch readers probably won’t know him, therefore we thought it a wonderful idea to introduce him. In the Netherlands, he made impact with this performance:

Kyteman wants to break down genre barriers and mixes them to, according to himself, “a collection of sounds, somewhere between opera, hip-hop, drum & bass, electro, minimalism and all kinds of other genres that I can’t even begin to describe, for I don’t have the words for them. All the instrumentals for this record were done in one take, with practically no edits whatsoever. So we played everything exactly as you hear it on the album.”

Here’s another sample (and his latest single) of what he can do:

Or check the complete version:

So, what do you think? Have you seen another newcomer surprising and pleasing you more in the last couple of years? If so, we’d sure be interested to hear who that is!

Keeping track of statistics

There are situations when you don’t have access to any log files or dashboard that allows you to see traffic statistics. For us, TechNet Wiki pages we’ve created are an example of this. Office 365 seems to be another example: at least we didn’t find it in the administration pages, any good tip for seeing Office 365 web traffic will be appreciated!http://statcounter.com/ allows you to add a simple HTML code snippet and then offers a dashboard for keeping record off the traffic.

Most active Wiki contributors

Last week, Margriet has been quite active in the TechNet Wiki community. To tell the truth it was to her own surprise (see http://social.technet.microsoft.com/wiki/contents/articles/default.aspx) that Margriet ranked quite high. Now it’s a game, lets see if Margriet can move up one or two places.

image

Going for a CAML ride

This article saved us some time, it’s a good reminder, maybe it will help you too: http://www.sharepoint-tips.com/2007/04/one-of-more-field-types-are-not.html It emphasizes that you should use internal field names in CAML queries and advises to use the U2U CAML Builder tool to get them for you.

Being featured…

The Wiki page http://social.technet.microsoft.com/wiki/contents/articles/10590.sharepoint-2010-best-practices-to-estimating-and-benchmarking-project-efforts.aspx is being featured on the home page of TechNet Wiki.

Quote from Ed Price:

“Congratulations on this article being featured on the home page of TechNet Wiki!”

You can see the nomination at

http://social.technet.microsoft.com/wiki/contents/articles/3568.technet-wiki-featured-article-nominees.aspx#SharePoint

SPMetal looses spaces in choice field

Recently, we were creating a web part that displays entities generated with SPMetal. One of the columns is a status field called MyStatus of type Choice. In the display, it just shows “InReview”, when the actual value is “In Review”.

The code does something similar to this:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;

namespace VisualWebPartProject1.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        AstroDataContext dc = new AstroDataContext(SPContext.Current.Web.Url);
        protected override void OnPreRender(EventArgs e)
        {
            var query = (from item in dc.MyPrintList
                                     select item).ToList<MyPrintBaseType>();

            gvOverview.AutoGenerateColumns = false;
            gvOverview.DataSource = query;
            gvOverview.DataBind();
        }
    }
}

The declarative part looks something like this:

<asp:GridView runat=”server” ID=”gvOverview” AllowPaging=”False”>
    <Columns>
        <asp:TemplateField HeaderText=”Print”>
            <ItemTemplate>
                <input type=”checkbox” id=’chkAvail<%#DataBinder.Eval(Container.DataItem, “Id”)%>’
                    value='<%#DataBinder.Eval(Container.DataItem, “Id”)%>’ checked />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText=”ID” DataField=”ID” />
        <asp:BoundField HeaderText=”Title” DataField=”Title” />           
        <asp:TemplateField HeaderText=”Status”>
            <ItemTemplate>
                <div id=”divStatus<%#DataBinder.Eval(Container.DataItem, “Id”)%>”>
                <%#DataBinder.Eval(Container.DataItem, “MyStatus”)%>                   
                </div>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText=”Date”>
            <ItemTemplate>
                <asp:Label ID=”Label1″ Text='<%#DataBinder.Eval(Container.DataItem, “MyDate”,”{0:dd-MM-yyyy}”)%>’
                    runat=”server” />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

This result be seen in the next figure.

image

So, somebody stole our spaces! Our immediate response to this brutal case of space theft was to find the bandit responsible for this. We had one main suspect…

SPMetal! When we took a look at the code generated by SPMetal, it’s quite clear why the spaces are missing. The original, full-blown, values are stored as attributes in the MyStatus enumeration. However, the actual names within the enumeration, as generated by SPMetal, are used when displayed in the SPGridView:

public enum MyStatus : int {

None = 0,

Invalid = 1,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value=”Unread”)]
Unread = 2,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value=”In Review”)]
InReview = 4,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value=”Accepted”)]
Accepted = 8,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value=”Denied”)]
Denied = 16,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value=”Remark”)]
Remark = 32,
}

 

As is explained in http://msdn.microsoft.com/en-us/library/ee537010.aspx , this is normal behavior. Since SPMetal generates partial classes, one way to get around it is to create a partial class for the entity representing your content type that provides a method or property that returns the attribute associated with a given enumeration value. Another way would be to generate an extension method that does the same. The implementation of such an extension method is shown in the answer in thread http://sharepoint.stackexchange.com/questions/21750/frustrated-linq-to-sharepoint-choice-values-losing-spaces .

Another way, and we guess the cleanest way if you’re only reading data, is to override the SPMetal defaults by using a Parameters XML file. See http://msdn.microsoft.com/en-us/library/ee535056.aspx for details.

In our case, we’ve saved the following XML in a file called params.xml:

<?xml version=”1.0″ encoding=”utf-8″?>
<Web xmlns=”http://schemas.microsoft.com/SharePoint/2009/spmetal”>
  <ContentType Name=”MyPrintBaseType” Class=”MyPrintBaseType”>
    <Column Name=”MyStatus” Member=”MyStatus” Type=”String” />
  </ContentType>
</Web>

This XML file says that we want to convert our MyStatus field to the type of String, which causes the original values to be included. See http://blogs.msdn.com/b/sharepointdev/archive/2011/05/03/using-linq-to-sharepoint-with-choice-fields.aspx , it also discusses a scenario where you want to write to a choice field too.

Then, we’ve generated our entities anew using the parameters XML file:

spmetal /web:http://astro /code:Astro.cs /parameters:params.xml

The end result meets our needs:

image

Print friendly list items addition

Instead of the ultimate print function listed in https://sharepointdragons.com/2012/05/05/print-friendly-list-items/ :

<script type=”text/javascript”>
jQuery(function () {
//alert(‘print’);
window.print();
});
</script>

It’s better to do it like this to print the actual contents of the dialog window:

$(window).load(function () {

window.focus();

window.print();

});

Cosmic and SharePoint

It can be hard to estimate how much time it will take to complete a SharePoint project. The usual approach is to do an “expert count”, in other words, have an expert (or more) estimate how long it will take to complete a project. Depending on the quality of the expert(s) and his/her team members, this can be a fine approach. It has one disadvantage though: it’ll make it really hard to do benchmarking and try to compare one project to another.
A more formalized way to go about it is to use a standard methodology for establishing the functional size of a SharePoint project expressed in function points. Although there are other methodologies, we’ll use the COSMIC Full Function Points methodology as the basis for analysis of the functional size of the project, as it focuses on the bare essentials. This is a difference from the more well known FPA methodology, but rest assured, COSMIC is also one of the 5 recognized ISO standards for functionality sizing software: http://en.wikipedia.org/wiki/Function_point .
After establishing the project functional size (and the great thing is, even if you apply COSMIC wrong, as long as you do it consistently, it’s still useful), the problem remains how to map these function points to a realistic amount of implementation hours. This knowledge can only be gained the hard way, based on experience. That’s where this Wiki page comes in, it relies on the feedback of SharePoint community members and offers an overview of what the community thinks is realistic.

Brief introduction of COSMIC

COSMIC breaks functional processes down to data movements. Each data movement corresponds to 1 COSMIC Functional Size Unit (CFSU). Each CFSU corresponds to a number of hours, i.e. it might take 8 hours to implement 1 CFSU. COSMIC discerns 4 different types of data movements:

  • E, Entry, a data movement that moves a data group/moves from a user/moves across a software boundary/moves into the functional process.
  • X, eXit, a data movement that moves a data group/moves from a functional process/moves across a software boundary/moves to the user that requires it
  • R, Read, a data movement that moves a data group from persistent storage (i.e. a database) to a functional process.
  • W, Write, a data movement that moves a data group from a functional process to persistent storage.

E and X data movements include formatting, presentation manipulations, simple validation, and processing required for routing. R and W data movements include simple processing, computations and other manipulations.
For more information, please refer to:

Learn by example

It’s probably unnecessary to point out that you’re not reading a comprehensive learning guide about Cosmic FFP. But still, let’s see how it works by learning from a simple example.

Suppose you have the following requirement: You need to build a visual web part that allows end users to enter an employee id. After that, the web part will look up all information it has related to this specific employee. Further suppose 1 CFSU for a visual web part takes 2 hours to implement. How much time will it take to implement this specific visual web part?

– Entering the employee id counts as an E (Entry): +1 CFSU.
– Retrieving employee data counts as an R (Read): +1 CFSU.
– Displaying employee data counts as an X (Exit): +1 CFSU.
– And probably you didn’t see this one coming: there’s also an X (Exit) for displaying any error and/or confirmation messages regarding the entire process.

This totals to 4 CFSU, which, in this example, leads us to believe that an estimation of 8 hours to implement this web part is reasonable.

Please note: As said before, no worries if you get a different answer. Even if you’re calculating it wrong, just as long as you do that consistently (meaning: you have your own approach to counting CFSU’s) Cosmic will still be useful to you.

What now?

The information in this article is based on the ongoing efforts of the following Wiki page: http://social.technet.microsoft.com/wiki/contents/articles/10590.sharepoint-2010-best-practices-to-estimating-and-benchmarking-project-efforts.aspx . Check it regularly for the most recent views on development times for specific SharePoint artifacts.