Archive

Kategorien

Links

Andere Blogs




ITaCS GmbH

May 162013

SPQuery for my tasks

Developing solution with multiple languages (or a language which is not English) sometimes can be a bit painful. To configure a Webpart to display only my tasks, I would filter for [Me] or [Ich].

image

To achieve the same via code / CAML, you can filter by UserID and not the string “Me”.

  1: <Where>
  2:   <Eq>
  3:     <FieldRef Name="AssignedTo" />
  4:     <Value Type="Integer">
  5:       <UserID />
  6:     </Value>
  7:   </Eq>
  8: </Where>
  9: <OrderBy>
 10:   <FieldRef Name="Status" />
 11:   <FieldRef Name="Priority" />
 12: </OrderBy>
This is just a reminder for me, so I can find the information more quickly. But maybe this is useful for some of you as well Smile

Published: 5/16/2013  1:29 PM | 0  Comments | 0  Links to this post
Tagged as: Development, SharePoint, SPQuery

Apr 242013

Do long running operations on SPListItem creation

Events on SPListItems like ItemAdding or ItemAdded are nothing new. Many of you have already used them. Recently I had a requirement to create a new SPSite, when an item in a list has been created. So an ItemReceiver was my choice.

But the customer wants something special Smile During the creation process, which takes some seconds, the user should see a loading animation.

image

Here comes the problem. The ItemEventReceiver is running in the background, and has no knowledge about the GUI process. Well, at least if it is running asynchronous. A very good explanation can be found here: Using synchronous "after" events (e.g. ItemUpdated) in SharePoint 2010.

The short summary: If you use synchronous events, they get executed in the same thread and you have the HttpContext and SPContext!

You already tried this and didn’t have the context objects?

image

image

Here comes the trick…

image

Grab the objects in the constructor, store them and use later when you need them.

  1: private SPContext _spContext;
  2: private HttpContext _httpContext;
  3: 
  4: public EventReceiver()
  5: {
  6:   _spContext = SPContext.Current;
  7:   _httpContext = HttpContext.Current;
  8: }
  9: 
 10: public override void ItemAdded(SPItemEventProperties properties)
 11: {
 12:   base.ItemAdded(properties);
 13:   try
 14:   {
 15:     if (_spContext == null)
 16:     {
 17:       // item has been created via code from timerjob. no context and no need to redirect
 18:       return;
 19:     }
 20:     string url = SPUrlUtility.CombineUrl(_spContext.Web.ServerRelativeUrl, "_layouts...") + properties.ListItemId;
 21:     _httpContext.Response.Redirect(url);
 22:   }
 23:   catch (ThreadAbortException e)
 24:   {
 25:     // occures if redirected
 26:   }
 27: }

Ok. We’ve successfully redirected to another page in our creation page, which can be a modal dialog or full frame page. I’ve not been able to use the Page to start a SPLongOperation with. A NullReference Exception has been thrown. So my solution was another Layouts-Page, which then starts the SPLongOperation. When it is done, the Layouts-Page is closed. By closing it, the modal dialog from the Item Creation process also vanishes.

I’ve chosen the ItemAdded and not ItemAdding event, because ItemAdding did not like the redirect. The item did not get created.

The Layouts-Page uses SPLongOperation e.g. in CreateChildControls.

  1: using (var longRunning = new SPLongOperation(Page))
  2: {
  3:   longRunning.Begin();
  4: 
  5:   // do your long running operation here
  6: 
  7:   longRunning.End(null, SPRedirectFlags.Default, Context, null, 
  8: "window.frameElement.commonModalDialogClose(1, null);");
  9: }
 10: 

After the operation has been executed, the SPLongOperation is ended and a script passed as last parameter in the End() method is executed. You don’t need script tags here.

To register the ItemEventReceiver to execute synchronously, use the following code.

  1: SPList list = ...
  2: 
  3: // attach EventReceiver
  4: var receiverDefinition = list.EventReceivers.Add();
  5: receiverDefinition.Type = SPEventReceiverType.ItemAdded;
  6: receiverDefinition.Assembly = "yourAssemblyFullName";
  7: receiverDefinition.Class = "Your EventReceiver class (incl. namespace)";
  8: receiverDefinition.Synchronization=SPEventReceiverSynchronization.Synchronous;
  9: receiverDefinition.Update();
 10: 
 11: list.Update();

Basically that’s it. A combination of known tasks to create a new solution.

Summary

You can show a work-in-progress dialog to a user, when a new SPListItem is created. Here are the steps:

  1. Use a synchronous asynchronous event Smile
  2. Redirect to a Layouts-Page
  3. Use the SPLongOperation class to do your work
  4. Have fun and happy customers

Published: 4/24/2013  3:56 PM | 0  Comments | 0  Links to this post
Tagged as: Development, SharePoint

Apr 172013

CKS - Dev for Visual Studio 2012

The Tools have been released for VS 2012. Great!

The CKS - Development Tools Edition for Visual Studio 2012 is a collection of Visual Studio templates, Server Explorer extensions and tools providing accelerated SharePoint 2010/2013 development based on Microsoft's SharePoint 2010/2013 development tools.

The current 1.0 release includes the following features:

  • Server Exploration from CKSDev 2010 v2.4 - Visual Studio 2012 version of the Visual Studio 2010 exploration. Includes all the existing server explorer features.
  • Quick Deploy extensions from CKSDev 2010 v2.4 - Visual Studio 2012 version of the Visual Studio 2010 quick deploy. Includes all the existing quick deploy features.

About the Community Kit for SharePoint

The Community Kit for SharePoint is a set of editions, components, tools and recommended documentation for SharePoint development. You are currently viewing the edition project site for the Development Tools Edition. To learn about the other editions and components you can go to http://www.communitykitforsharepoint.org/default.aspx.

You can read more and download the tools here: http://visualstudiogallery.msdn.microsoft.com/cf1225b4-aa83-4282-b4c6-34feec8fc5ec

A CodePlex page also exists: http://cksdev.codeplex.com


Published: 4/17/2013  7:08 AM | 0  Comments | 0  Links to this post
Tagged as: SharePoint, Products, CodePlex

Mar 052013

Now Available: Office Developer Tools for Visual Studio 2012

Finally! Now Available: Office Developer Tools for Visual Studio 2012

There are some points to mention, where the final release of the tools differ from previous preview releases:

  • validation experience that helps you to find and fix common errors prior to submitting your apps to the Office Store
  • A continuous integration workflow
  • Windows Azure cloud service projects for creating provider-hosted Apps
  • A dramatically improved Workflow designer

The download link: http://aka.ms/OfficeDevToolsForVS2012


Published: 3/5/2013  5:04 PM | 0  Comments | 0  Links to this post
Tagged as: SharePoint, Development