SharePoint Dragons

Nikander & Margriet on SharePoint

Process Monitor

Process Monitor is an advanced tool that can monitor real-time file system, registry and process thread activity. Therefore, it’s a valuable tool for diagnosing problems in underlying frameworks. This article contains a nice example of that: http://bernado-nguyen-hoan.com/2011/09/08/setting-up-trusted-domain-in-sharepoint-2010-an-exception-occurred-in-ad-claim-provider-when-calling-spclaimprovider-fillsearch-requested-registry-access-is-not-allowed/ Process Monitor can be downloaded at http://technet.microsoft.com/en-us/sysinternals/bb896645

Access the querystring in an ItemAdded event receiver

You can’t access the HttpContext within an ItemAdded event receiver, which makes sense, as there is none anymore. If you want to access the querystring in it, you can retrieve it in the ItemAdding event and pass it to the ItemAdded event via the HttpRuntime cache: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/421a6a2b-22ce-4aa8-8d14-944493eddc6c

Searching for .cs, .vb, .sql and .java files

Interesting forum thread on searching for the mentioned uncommon file types in SharePoint: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/eeb1fd03-a579-4665-a396-263d5a5ddf4f

Getting the current user in InfoPath without writing code

Camlex.NET

Camlex.NET simplifies the creation of CAML queries: http://camlex.codeplex.com/ It’s not very popular yet, but it’s interesting. It seems to be offering an easier, more familiar way to construct CAML queries on the fly using lambda expressions and a fluent interface. Not sure how this compares to SPMetal, which requires you to generate classes beforehand before you’ll be able to use Linq to query object structures (which then get translated to CAML). At first glance SPMetal seems to be even easier, because it supports strong typing and concurrency conflict resolution. Tell us what you think?

A web part editor part containing a drop down list

This post contains the code required for making a SharePoint 2010 web part that uses an editor part that contains a drop down list.

Here’s the code for the web part editor part:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

namespace SharePointProject3.WebPart1
{
    public class WebPart1EditorPart : EditorPart
    {
        // Reference to the web part that uses this editor part, the parent web part needs to implement the IWebEditable interface to support custom editing controls
        protected WebPart1 ParentWebPart { get; set; }
        protected DropDownList EditorChoices { get; set; }

        /// <summary>
        /// Does editor part init settings
        /// </summary>
        public WebPart1EditorPart()
        {
            Title = “Make a choice – good name here”;
        }

        /// <summary>
        /// Creates the dll
        /// </summary>
        protected override void CreateChildControls()
        {
            EditorChoices = new DropDownList();
            EditorChoices.Items.Add(new ListItem(“AAA”, “1”));
            EditorChoices.Items.Add(new ListItem(“BBB”, “2”));
            EditorChoices.Items.Add(new ListItem(“CCC”, “3”));
            Controls.Add(EditorChoices);

            base.CreateChildControls();
            ChildControlsCreated = true;
        }

        /// <summary>
        /// Reads current value from parent web part and show that in the ddl
        /// </summary>
        public override void SyncChanges()
        {
            EnsureChildControls();
            ParentWebPart = WebPartToEdit as WebPart1;

            if (ParentWebPart != null && WebPartManager.Personalization.Scope == PersonalizationScope.Shared)
            {
                ListItem item = EditorChoices.Items.FindByValue(ParentWebPart.MyEditorPartChoice);
                if (item != null) item.Selected = true;
            }
        }

        /// <summary>
        /// Applies change in editor part ddl to the parent web part
        /// </summary>
        /// <returns></returns>
        public override bool ApplyChanges()
        {
            try
            {
                EnsureChildControls();
                ParentWebPart = WebPartToEdit as WebPart1;

                if (ParentWebPart != null && WebPartManager.Personalization.Scope == PersonalizationScope.Shared)
                {
                    ParentWebPart.MyEditorPartChoice = EditorChoices.SelectedValue;
                }

                // The operation was succesful
                return true;
            }
            catch
            {
                // Because an error has occurred, the SyncChanges() method won’t be invoked.
                return false;
            }
        }
    }
}

Here’s the code for the web part itself:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;

namespace SharePointProject3.WebPart1
{
    [ToolboxItemAttribute(false)]
    public class WebPart1 : WebPart, IWebEditable
    {
        protected override void CreateChildControls()
        {
            var lbl = new Label();

            if (MyEditorPartChoice == null)
                lbl.Text = “Make a choice first”;
            else
                lbl.Text = “The value from the editor part choice: ” + MyEditorPartChoice;
           
            Controls.Add(lbl);
        }

        /// <summary>
        /// Contains the value of the choice in the editor part drop down list
        ///
        /// Set the Personalizable attribute to true,
        /// to allow for personalization of tabs by users.
        /// This causes  this property to be shown in the web part tool pane and lets SharePoint take care of the storage/retrieval of this property in the SharePoint content database.
        /// </summary>
        [Personalizable(true)]
        public string MyEditorPartChoice { get; set; }

        /// <summary>
        /// Creates custom editor parts here and assigns a unique id to each part
        /// </summary>
        /// <returns>All custom editor parts used by this web part</returns>
        EditorPartCollection IWebEditable.CreateEditorParts()
        {
            var editors = new List<EditorPart>();           
            var editorPart = new WebPart1EditorPart();
            editorPart.ID = ID + “_editorPart”;
            editors.Add(editorPart);

            return new EditorPartCollection(editors);
        }

        /// <summary>
        /// Returns parent web part to editor part
        /// </summary>
        object IWebEditable.WebBrowsableObject
        {
            get { return this; }
        }
    }
}

Changing a SharePoint list URL

Not only can you change the name of a list title, using SharePoint Designer you can also change the URL itself:

1: You must be a site collection admin.

2: Open the site in SharePoint Designer 2010

3: Locate “All Files” at the bottom of the left hand navigation pane, which will open the main “All Files” pane on the right.
** “All Files” is not visible if your do not have the appropriate permissions.**

4: click (once) on “Lists” in the main “All Files” pane.

5: Right Click on the list that you want to change the URL/Web Address for and choose “Rename”

Taken from: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/03d0aba0-9533-4237-8459-2f3a8e2a03e0

Sending e-mail from SharePoint Online

When creating emails in workflows in SharePoint Online, they’re being sent from the following e-mail address: admin@microsoftonline.com This can’t be changed as the e-mail address is maintained at the farm level and therefore is the same for all customers.

What to do? Create an e-mail forwarding account that SharePoint Online sends to. Use custom code to process the incoming e-mails and send them out via the “official” e-mail address. For more info, see: http://social.technet.microsoft.com/Forums/en-US/onlineservicessharepoint/thread/22677259-039d-4e96-ad88-d7bb28eabeec

More about performance

This is a nice link that contains info about performance stress and load testing: http://blogs.msdn.com/b/sanjaynarang/archive/2010/04/20/sharepoint-2010-performance-stress-load-testing.aspx Also, regularly keep checking http://social.technet.microsoft.com/wiki/contents/articles/7926.sharepoint-2010-tips-for-dealing-with-performance-issues.aspx , it’s the best resource out there about this topic. If you feel the last comment is unfair, you’d be absolutely right since we’ve created that Wiki page ourselves. We’d love you to prove us wrong though, just add a comment about it and we’ll post it!

SharePoint Taxonomy info nugget

Sometimes you come across these little pieces of knowledge. In this case, we came across this little nugget of info about taxonomy: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/5f81afd3-8c77-4cf6-a924-19498d3f15d8