Archive for September, 2008

I have previously talked about how you manually can configure your SharePoint environment to enable .NET 3.5. My approach were to always do this manually, but it seems that there’s a sweet feature for this purpose created, automating this process.

As a tip from Jeremy Thake, I’m posting the link to a CodePlex project called “Features” which obviously have a feature that deals with configuring your web application without any manual steps like modifying xml snippets in web.config.

Even though the manual steps I’ve provided in my blogpost only takes about 1-2 minutes to perform, this approach eliminates the human facor – which often is the cause to a lot of headaches!

Thanks for the tip Jeremy, and hope everyone else will find this interesting aswell!

More on .NET 3.5 to come later.

Author: Tobias Zimmergren
Blog: http://www.zimmergren.net

Introduction

In my previous article title "How to: Get up and running with .NET 3.5 in your SharePoint environment" I talked about how you can manually set up your SharePoint environment for use with Microsoft .NET Framework 3.5.

In this article I will talk about how you can incorporade some of the technologies used in .NET 3.5 to query a SharePoint list. More precisely, I will talk about how you easily can use LINQ from the .NET 3.5 framework to get started with .NET 3.5 in SharePoint.

A more in-depth article might be posted later, but this one is simply providing simple code instructions to what a Web Part that utilizes LINQ can look like!

Prerequisites

In order to follow along with this walkthrough, you should have the following bulletpoints checked:

Creating a custom Web Part which utilizes .NET 3.5 in SharePoint

The code below will give you the heads up on how to fetch the SPListItem objects from an SPList object and sort them alphabetically. You can of course use the ‘where’-clause with LINQ aswell to filter out which objects (SPListItem objects) to fetch from the SPList.

Example task list to fetch the data from:
image

Using the following code, I’ve used LINQ to retreive all the list items and sort them ascending by title!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Zimmergren.net35.LINQWebPartSample
{
    public class SPLINQ : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            SPList taskList = SPContext.Current.Web.Lists["Tasks"]; 

            // Get items, order by title alphabetically and assign to taskListItems
            var taskListItems = from SPListItem tItem in taskList.Items
                                orderby tItem.Title
                                ascending select tItem;
 

            foreach (SPListItem taskItem in taskListItems)
                writer.WriteLine(taskItem.Title + "<br/>n");
        }
    }
}

The bold text in the above code block is the LINQ statement to fetch all items in the SPList and order them ascending by Title. You can of course make much more complex queries using LINQ in order to fetch other objects based on different criteria.

This will produce a simple output like this, sorting the items alphabetically:
image

Summary and Download

This was a very (very) basic and simple example of how you can use any .NET 3.5 technology to get started with some new cool stuff.

I utilized a basic LINQ expression in this article which of course can be heavily modified if you want to retreive other things from your list(s). Perhaps a future article will take on some more advanced LINQ expressions in conjunction with SharePoint?! :-)

Anyway, you can download the sample project from here: Zimmergren.net35.LINQWebPart.zip

Thanks for tuning in and please leave a comment

As always, there’s plenty of readers but few people showing their appreciation through the comments – please leave a comment :)

Hope it helps :-)

Since I’ve been a bit on the lazy side when it comes to the blog (due to multiple reasons..), I’m thinking about writing up an article-series where I’ll talk about .NET 3.5 and what it has to offer when used in conjunction with SharePoint. Any input is welcome, of course :)

Introduction

In this article I will try to get you up and running with the .NET 3.5 framework in your SharePoint environment, just like I’ve previously described how you can get AJAX and Silverlight 2.0 up and running:

I will now let .NET 3.5 be a part of some of my upcoming SharePoint projects, and because of that I thought it could be a good thing to blog about it if there’s anyone out there looking to do the same!

Prerequisites before we get started

In order to follow along, I assume the following few bulletpoints are in place:

  • Microsoft .NET 3.5 Framework is installed on the front-end server
  • You already have got a Web Application on which you want to do these changes

Add support for .NET 3.5 in SharePoint (WSS 3.0 or MOSS 2007 alike)

Here you will find a manual step by step instruction on what web.config values to set in order for .NET 3.5 to work properly with your SharePoint installation.

Note: I’ve added some linebreaks in order for the text to show up properly in my blog, you may remove them if you want your web.config to be pretty ;)

Note2: All additions to any elements in the web.config file should be added at the bottom/end of each element unless excplicitly stated otherwise.

1) Add the following snippet inside the <configSections> element

<sectionGroup name="system.web.extensions"
                type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35">
    <sectionGroup name="scripting"
                type="System.Web.Configuration.ScriptingSectionGroup,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35">
       <section name="scriptResourceHandler"
                type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35" requirePermission="false"
                allowDefinition="MachineToApplication"/>
       <sectionGroup name="webServices"
                    type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
                    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                    PublicKeyToken=31BF3856AD364E35">
        <section name="jsonSerialization"
                type="System.Web.Configuration.ScriptingJsonSerializationSection,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35" requirePermission="false"
                allowDefinition="Everywhere" />
        <section name="profileService"
                type="System.Web.Configuration.ScriptingProfileServiceSection,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35" requirePermission="false"
                allowDefinition="MachineToApplication" />
        <section name="authenticationService"
                type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35" requirePermission="false"
                allowDefinition="MachineToApplication" />
        <section name="roleService"   
                type="System.Web.Configuration.ScriptingRoleServiceSection,
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
                PublicKeyToken=31BF3856AD364E35" requirePermission="false"
                allowDefinition="MachineToApplication" />
      </sectionGroup>
    </sectionGroup>
  </sectionGroup>

2) Add the following snippet inside the <pages> element

<controls>
  <add tagPrefix="asp" namespace="System.Web.UI"
        assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>
  <add tagPrefix="asp" namespace="System.Web.UI.WebControls"
        assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>
</controls>

3) Add the following snippet inside the <assemblies> element

<add assembly="System.Core,
    Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions,
    Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions,
    Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq,
    Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=B77A5C561934E089"/>

4) Add the following snippet inside the <httpHandlers> element

<add verb="*" path="*.asmx" validate="false"
    type="System.Web.Script.Services.ScriptHandlerFactory,
    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false"
    type="System.Web.Script.Services.ScriptHandlerFactory,
    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd"
    type="System.Web.Handlers.ScriptResourceHandler,
    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35" validate="false"/>

5) Add the following snippet inside the <httpModules> element

<add name="ScriptModule"
    type="System.Web.Handlers.ScriptModule,
    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35"/>

6) Add the following snippet inside the <SafeControls> element

<SafeControl Assembly="System.Web.Silverlight,
            Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            Namespace="System.Web.UI.SilverlightControls" TypeName="*" Safe="True" />
<SafeControl Assembly="System.Web.Extensions,
            Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            Namespace="System.Web.UI" TypeName="*" Safe="True" />

7) Add the following snippet inside the <configuration> element

    <system.web.extensions>
      <scripting>
        <webServices>
        </webServices>
      </scripting>
    </system.web.extensions>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <add name="ScriptModule" preCondition="integratedMode"
            type="System.Web.Handlers.ScriptModule,
            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
            PublicKeyToken=31bf3856ad364e35"/>
      </modules>
      <handlers>
        <remove name="WebServiceHandlerFactory-Integrated" />
        <add name="ScriptHandlerFactory" verb="*"
            path="*.asmx" preCondition="integratedMode"
            type="System.Web.Script.Services.ScriptHandlerFactory,
            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
            PublicKeyToken=31bf3856ad364e35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*"
            path="*_AppService.axd" preCondition="integratedMode"
            type="System.Web.Script.Services.ScriptHandlerFactory,
            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
            PublicKeyToken=31bf3856ad364e35"/>
        <add name="ScriptResource" preCondition="integratedMode"
            verb="GET,HEAD" path="ScriptResource.axd"
            type="System.Web.Handlers.ScriptResourceHandler,
            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
            PublicKeyToken=31bf3856ad364e35" />
      </handlers>
    </system.webServer> 
    <system.webServer>
       <validation validateIntegratedModeConfiguration="false"/>
       <modules>
         <remove name="ScriptModule" />
         <add name="ScriptModule" preCondition="managedHandler"
            type="System.Web.Handlers.ScriptModule,
            System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
            PublicKeyToken=31BF3856AD364E35"/>
       </modules>
       <handlers>
         <remove name="WebServiceHandlerFactory-Integrated"/>
         <remove name="ScriptHandlerFactory" />
         <remove name="ScriptHandlerFactoryAppServices" />
         <remove name="ScriptResource" />
         <add name="ScriptHandlerFactory" verb="*" path="*.asmx"
            preCondition="integratedMode"
            type="System.Web.Script.Services.ScriptHandlerFactory,
            System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
            PublicKeyToken=31BF3856AD364E35"/>
         <add name="ScriptHandlerFactoryAppServices" verb="*"
            path="*_AppService.axd"
            preCondition="integratedMode"
            type="System.Web.Script.Services.ScriptHandlerFactory,
            System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
            PublicKeyToken=31BF3856AD364E35"/>
         <add name="ScriptResource" preCondition="integratedMode"
            verb="GET,HEAD" path="ScriptResource.axd"
            type="System.Web.Handlers.ScriptResourceHandler,
            System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
            PublicKeyToken=31BF3856AD364E35" />
       </handlers>
    </system.webServer>

8) You’re done

When you’ve added the needed tags, you’re all set – you can now run your .NET 3.5 applications inside SharePoint (of course, this applies to the web application where you just added these settings.

To see that your site still works, do the following:

  • IISRESET
  • Launch your site where you’ve made the changes!
  • Cross your fingers

Cool, what’s next?

Well, if you’ve managed to get your site up and running – you can now create webparts, features, controls or whatever you’d like to create and have them published to your site.

This article describes how you do these things manually, but what if you want to do these things automatically somehow? Is that possible?
- Yes, but that’s going to be covered in an upcoming blogpost

Please leave some comments

As you might know, I like to get feedback and usually answers all mails/comments when I’ve got the time. Please leave any feedback, suggestions or opinions in the comments below or mail me/use the MSN gadget.

Thanks for tuning in, now I’m feeling the blog-flow again – cheers

Going offline – Finally the vacation has arrived!

September 4th, 2008 by Tobias Zimmergren

As you may have noticed, I havn’t been really active here the last couple of weeks since I’ve been fully absorbed with a bunch of cool SharePoint projects lately. However, the time has come for me to go on a well-deserved vacation for 2 weeks. During that period, you will probably not hear a word from me.

When I’m back, I’ve got some cool ideas to blog about – see you then!

Perhaps a little bit of golf on Mallorca?

And, perhaps a whole lot of sun on Mallorca?