SharePoint 30 minute Timeout for forms

I noticed that when you open a form in SharePoint and start to fill it out, SharePoint will time out that form after 30 minutes.

If you are filling out a form with a lot of data, or if you have to stop working on a form for a few minutes, this is very annoying because after 30 minutes all the work will be gone and you have to start filling the form all over again.

Here’s the solution:

PS> $SPSite = Get-SPSite("https://portal.lab.intern")
PS> $webApp = $SPSite.WebApplication
PS> $webApp.FormDigestSettings

Enabled Expires Timeout UpgradedPersistedProperties
——- ——- ——- —————————
True False 0:30:00 {}

PS> $webApp.FormDigestSettings.Timeout = New-TimeSpan -Hours 8
PS> $webApp.Update()

Impersonation in CRM Plug-In and Workflow – the easy way

Some time ago I wrote a post about impersonation in dynamics crm plug-ins.

Today I found a much easier solution: use the impersonated organizationService from localcontext.

IOrganizationService service = localContext.OrganizationServiceImpersonated;

Ok, first you have to create this property. Do this in Plugin.cs, which gets generated by Visual Studio. Create the property:

internal IOrganizationService OrganizationServiceImpersonated
    private set;

Add the following line to the constructor of LocalPluginContext:

// Use the factory to generate the impersonated Organization Service.
this.OrganizationServiceImpersonated = factory.CreateOrganizationService(null);

Instead of null you can also pass a systemusers GUID. Null will impersonate as systemadministrator.

And when you are just there, also set the ServiceProvider correctly, so that it’s not null. Then the whole constructor looks like this:

internal LocalPluginContext(IServiceProvider serviceProvider)
    if (serviceProvider == null)
        throw new ArgumentNullException("serviceProvider");

    // 1. extra line: Set LocalContext ServiceProvider
    this.ServiceProvider = serviceProvider;

    // Obtain the execution context service from the service provider.
    this.PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    // Obtain the tracing service from the service provider.
    this.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    // Obtain the Organization Service factory service from the service provider
    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    // Use the factory to generate the Organization Service.
    this.OrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

    // 2. extra line: Use the factory to generate the impersonated Organization Service.
    this.OrganizationServiceImpersonated = factory.CreateOrganizationService(null);

To get impersonated service in Workflows is a little easier:

var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
var service = serviceFactory.CreateOrganizationService(null);      //Create impersonated service

CustomAction isn’t showing for a content type

I ran into this problem today. I created a CustomAction that should show up in the DisplayForm of all Items having a specific content type, but it didn’t.

Here’s the simple solution:

It’s causing problems when content types don’t have all capitals in the identifier, both for the definition and when using. So I changed the RegistrationId to the following:

Failed to create receiver object from assembly

I added a new Feature with EventReceiver to my Solution. While trying to activate this WebApplication feature I got the errormessage, that Sharepoint “Failed to create receiver object from assembly“.

What caused the error?

The SharePoint Timer service cached the old DLL. After re-deploying my solution the cache wasn’t cleared. The reference to my EventReveiver wasn’t found in the old DLL.

What’s the solution?

Restart the SharePoint Timer Service on all servers in the farm.

A proxy type with the name account has been defined by another assembly

I wanted to display different entities from Dynamics CRM in my SharePoint site using the CRM webservice. My code worked while I only had one solution, connection to CRM, deployed on my server. When I wrote a second application that is also using the webservice, I got the following error:
“A proxy type with the name account has been defined by another assembly.”

Here’s the solution. You just have to add a new ProxyTypesBehavior:

ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri(@"[...]/XRMServices/2011/Organization.svc"));
OrganizationServiceProxy client = new OrganizationServiceProxy(orgConfigInfo, credentials);
client.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));

Create records in CRM 2011 using the CRM Web Service

When I began to create records in CRM using the webservice, I started with records containing simple text fields. And there was no problem. The following method creates a new contact entity in CRM:

public static Guid createCandidate(OrganizationServiceClient serviceProxy, string firstname, string lastname, string email)

Entity application = new Entity() { LogicalName = "contact" };

// Set Contact Properties
AttributeCollection Attributes = new AttributeCollection();

Attributes.Add(new KeyValuePair<string, object>("firstname", firstname));
Attributes.Add(new KeyValuePair<string, object>("lastname", lastname));
Attributes.Add(new KeyValuePair<string, object>("emailaddress2", email));

application.Attributes = Attributes;

//Create Contact
Guid appGuid = serviceProxy.Create(application);

return appGuid;

But then I also wanted to fill OptionSet fields (DropDowns) and ReferenceEntity fields (LookUp). But the Webservice always threw an exception:

Die InnerException-Nachricht war “Der Typ “*.OptionSetValue” mit dem Datenvertragsnamen “OptionSetValue:” wurde nicht erwartet. Fügen Sie alle statisch nicht bekannten Typen der Liste der bekannten Typen hinzu. Verwenden Sie dazu z. B. das Attribut “KnownTypeAttribute”, oder fügen Sie die Typen der an DataContractSerializer übergebenen Liste von bekannten Typen hinzu.”.

After a long time I found the solution here:

1. Create a new class in your project with name you prefer.

2. Keep the namespace of this class similar to your Reference.cs (This is important so do not forget it)

3. Now create partial classes as below

public partial class Entity { }

public partial class EntityCollection { }

public partial class OrganizationRequest { }

4. Now go to your actual code, and for lookup field use like this:

Attributes.Add(new KeyValuePair<string,object>("parentcustomerid", new EntityReference() {Id = t.Id, LogicalName= t.LogicalName}));

5. Build the solution

Now everything should work as expectedt!

How to get the assembly public key token using Visual Studio 2012

If you want to register a WorkflowActivity as safe in Webconfig you need the public key token from the dll.


<authorizedType Assembly=”Testprojekt, Version=, Culture=neutral, PublicKeyToken=b04480df764d9b77″ Namespace=”Testprojekt” TypeName=”*” Authorized=”True” />

1. On your SharePoint Server in Windows starmenue, open the “Developer Command Promt for VS2012”

2. In commandprompt type “sn -T *path to your dll*”