search blog
most popular
MCP MCTS MCT MVP

My most popular SharePoint posts of 2009

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

As per requests, I have put together a small list of my post popular and most read blog posts of 2009.

All in all, the year of 2009 was awesome - and we've only got even more awesome things to look forward to in 2010.

But to get on with it, here's my "Top 10 Most Popular SharePoint Posts" of 2009!

My Top 10 Most Popular SharePoint Posts - 2009

  1. MOSS 2007: Getting Started with the Business Data Catalog
    1. Related: Write your first BDC Web Part
  2. WSPBuilder - Walkthrough of the Visual Studio Add-in
  3. Introduction to SharePoint Online
  4. SharePoint Online - Customization
  5. SP 2010: Getting started with the Client Object Model
    Although this was very recently posted, it has gained a lot of popularity and is quickly moving up the list of most read posts.
  6. Recover/Fetch your Application Pool Password
  7. How To: SharePoint and Silverlight - Part 1
  8. Upload a document to a SharePoint Document Library programmatically (SharePoint Object Model)
  9. Debugging your code execution for anonymous users in SharePoint 
  10. 10 Free SharePoint Themes - Visual Overview

Summary

A very short list of the most viewed articles I wrote in 2009. There's plenty more of course, but to keep it short and concise I chose to go with the Top 10 as requested :-)

There's also another cool way to keep track of popular posts in the SharePoint community, and that's using PostRank. Visit this URL: http://www.postrank.com/topics/sharepoint and you'll be presented with popular blogs about SharePoint where you can easily find new content to read.

As for 2010, we've got some really fancy stuff to look forward to - and I've written a few posts about SharePoint 2010 to cover some of the new aspects for developers. Keep an eye out for them.

Enjoy this simple post. I'm still on vacation, so I'm not going to be much elaborate than this ;-)


Published: Jan-04-10 | 4 Comments | 0 Links to this post

SharePoint BDC Part 1: Getting Started with the Business Data Catalog

Author: Tobias Zimmergren
URL: http://www.zimmergren.net | http://www.tozit.com 

Introduction

In this article I will guide you through the very basics of getting started with Business Data Catalog, BDC:

  1. Install the AdventureWorks 2008 Sample Databases
    1. We will use this database as our example for retrieving data using the BDC.
  2. I will step you through the simple process of creating your ADF (Application Definition File)
    1. We will use this file as our import connection
  3. I will guide you through how we can import this ADF file and create our BDC Application
  4. Lastly, I will guide you through the process of creating a basic site and use some of the basic BDC Web Parts

Install the AdventureWorks sample database

  • You'll need to go and download the AdventureWorks sample databases
    image

  • Just finish the installation by clicking next a couple of times and let the installer do it's normal Microsoft-installer magic.
  • You should now see a couple of new databases in your SQL Server Management Studio:
    image
    AdventureWorks, AdventureWorks2008, AdventureWorksDW, AdventureWorksDW2008, AdventureWorksLT, AdventureWorksLT2008

Alright - We've got our databases, now we need to start thinking about how we will get data from our SQL server into SharePoint. This is done by creating/generating an Application Definition File (ADF) as you will see in the next section.

Creating the ADF (Application Definition File)

Alright, there's a few different options to create your ADF (Application Definition File). I will show you how to get started with using the free tool called "Application Definition Editor" that comes with the latest SharePoint Server SDK.

Note: See the bottom section in this article for a summary of links to all resources mentioned in the article.

After you have installed the latest SDK, you can choose to install the "Microsoft BDCTool" located here by default: "C:\Program Files\2007 Office System Developer Resources\Tools\BDC Definition Editor". Which will give you the following item in your Start Menu:
image

Launch the BDC Application Definition Designer

Click the application and launch the editor. You will see an interface like this:
image

Create or import your ADF file

There's basically two alternatives when it comes to editing an ADF (Application Definition File).
One is to create a new one (which I will guide you through first), and the other is to import an existing one (which I will show you after the first alternative).

Alt 1) Creating our own ADF file
Now we're going to connect to our newly created sample-databases and create an ADF file for use with those databases.
  • Click on ADD LOB System
  • Choose Connect To Database
  • You will see a nice popup-dialog where you will be able to enter the connection details to your desired database
    • Enter your connection details, example:
       image
  • You are presented with the "Designer Surface" that looks something like this:
    image
  • In our case, we're going to use the table called "vEmployee" which exist in the AdventureWorks database in order to pull out some information about our employees.
    • Search for the table called vEmployee and drag it out to the Design Surface
    • Search for the table called vEmployeeDepartments and drag it out to the Design Surface
    • It should look something like this:
      image
    • Make any necessary changes, then click OK
    • You'll see a view similar to this one after some tweaking:
      image 
    • After you've done the necessary changes to your configuration, making sure it's a valid ADF with proper filters, enumerators and methods or whatever you need in your application then smile, because we're done with that part!
Alt 2) Importing an existing ADF file

If you don't want to do everything from scratch or you've already got an ADF file that you wish to modify, you can do so by importing an existing ADF file into the Definition Editor. Here's how:

  • Open the BDC Definition Editor tool, then click the "Import" button in the menu:
    image
  • Browse to your existing ADF file and choose to import it. Simple as that.
    (I am importing a file called BDCAWDW.xml, which contains definitions for Product, Reseller, ProductSubcategory, ProductCategory as shown below)
  • You'll see the imported ADF file's structure immediately in the designer, under the prerequisite that your SQL connection string in the ADF file is valid:
    image 

Note: I will not detail how you create filters, finders, methods etc. in this article. You can read more about that here:
http://msdn.microsoft.com/en-us/library/ms145931(SQL.90).aspx

I may cover the topic of ADF-functionality in another article later on.

Generate the ADF file from the designer

I really don't need to tell you this, but there's a button called "Export" which you use to export the definition you've created using the definition editor to an xml file:
image

Import the ADF file

If we have gotten this far, we might as well get the last few bits in place.
What we now need to do is to import our ADF file into SharePoint, since that's where it should reside. Follow along with these few simple steps to make sure you're properly importing your file into SharePoint.

  • Navigate to your Shared Services Provider Administration site (You can access your SSP through Central Administration)
  • You are presented with a section called "Business Data Catalog" where you'll find a bunch of different alternatives.
  • Make sure you have the permissions to modify the BDC (See the link Business Data Catalog permissions)
  • Click "Import application definition"
    image  
  • Browse for your .xml file and click "OK":
    image
  • You'll see a progress bar (You don't see that a lot in SharePoint. I love it!), telling your how the import process is going:
    image
  • When it's done, you'll click "OK" and be presented with an overview of your imported BDC Application:
    image
Configure permissions on the BDC Application Definition

In order for all users to be able to select/read data from your BDC Application, you'll need to make sure they've got the appropriate permissions to actually do so.

Usually I do this setting on each of the imported entities, in case you want specific permissions on different entities - instead of on the entire application.

  • Select the DropDown list on your first entity and choose "Manage Permissions":
    image 
  • Choose "Add Users/Group":
    image
  • Enter "NT AUTHORITY\AUTHENTICATED USERS" and choose "Select in Clients":
    image
  • Repeat these steps for the other entity as well.
  • You're done.

Now we have created or imported an ADF file with the Business Data Catalog Definition Editor tool, exported it to an .xml file, imported it into SharePoint, set basic permissions on the entities.

Next, we should make sure that the application works in SharePoint by adding a Business Data Catalog-WebPart to a page.

Use the basic built-in BDC Web Parts

Awesome. Now that we have gotten this far by importing an ADF file into SharePoint and set appropriate permissions on the entities - We're ready to actually use the ADF connection to view stuff in our database.

Note: I have created a new blank site where I can easily show the built-in BDC Web Parts - so that's where I am adding my Web Parts.

 

  • Add two Web Parts to your page called "Business Data List" and "Business Data Item":
    (Note that when you've configured a BDC application, you'll see the Business Data web parts)
    image
  • Choose to edit the properties of the Business Data List Web Part:
    image
  • Click the Browse-icon to the right to pop up the BDC entity chooser:
    image
  • It will present you with the following interface (note, BDC applications will of course vary depending on what you have imported..):
    image 
  • Double click the "Employee" type, and then click "OK" in your Web Part property window.
  • Repeat this process for the "Business Data Item" Web Part, and select "Employee" in the BDC Type Picker as well.

Now we've got one BDC List Web Part which will list all employees, and one BDC Item Web Part that will display details about the employee we select.

In order for this to work we must connect the two Web Parts.

  • Edit menu of your Web Part -> Connections -> Send Selected item To -> Employee
    image

Test our BDC Application out, and make sure it works!

  • Choose "LastName" then "contains" and enter "smith":
    image
  • Select one of the results by clicking the radiobutton to the left, and see that the result (details) about the Employee shows up in the connected Web Part:
    image 

Resources and links

Summary

This article is a basic step-by-step guide to getting started with BDC in MOSS 2007. I've shown you every step from creating the databases required (in our case some sample databases) to creating the ADF file and to finally utilize the BDC connection from a site, using the BDC Web Parts.

In an upcoming post I will talk about how you can create your own BDC Web Parts! Keep your eyes open!


Published: Jun-25-09 | 31 Comments | 0 Links to this post

Debugging your code execution for anonymous users in SharePoint

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

Introduction

Often when developing solutions that has anonymous users enabled, it can be hard to debug them from your local machine - because when you reach a point in your code where permissions higher than anonymous is required, SharePoint automatically tries to identify the user.

This means that if you're running local development, and is browsing as an anonymous user - everything can be fine until you hit a line of code in your application that requires authentication, you are then automatically logged in.

This makes it rather hard for anyone to truly debug their solutions in anonymous mode.

With this article I'm laying out the tips that I'm using to debug application requiring anonymous users, and making sure that I don't step up my privileges if the application needs to - I will now get an access denied instead.

Featured Solution that I am using

  • Enable Anonymous access for your web application
  • Enable anonymous access for your site and lists
  • Enable Remote Desktop on your development machine
    • If it is a virtual machine, you'll also need to give it access to the internet or at least the local network so you can RDP to it using Remote Desktop.
  • Hook up your Visual Studio debugger to the IIS worker process so your breakpoints can hit
  • Use the web browser on your LOCAL machine (not the development machine) to browse your site (remember, it has to be an IP reachable from the local machine - make sure your network settings are valid)
    • This ensures that whenever you hit a point in your code that doesn't allow anonymous users, it can not impersonate the account of the logged in user, which will result in an access denied exception. (Yes, this is where your breakpoints and debugging skills come in)
  • Now, when the breakpoint has hit - simply remote to your development machine (or use the lagged-out funked-up VPC console.. (no, use RDP!!)) and step through the code, as the breakpoint has hit!

Summary

Debugging anonymously accessible code can be a bit of a pain, but following my mentioned recommendations should make it a bit easier.

I tend to use this technique whenever I'm playing around with anonymous access, least-privilege code and things like that.

Hope it can help someone.


Published: Jun-05-09 | 3 Comments | 1 Link to this post

Recommended articles related to SharePoint

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

Introduction

I use FeedReader to manage all my RSS feeds, and sometimes I tag some of the articles as "favorite" or "starred" articles - so I easily can find them when needed.

With that said, here's some of the articles I've been tagging as recommended reading during the last couple of weeks/month.

Note: There's plenty of more fish in the sea, these are just some of the tagged posts I've been looking at and I recommend reading.

Recommended reading, in no particular order

SharePoint Governance and Get Your Project Started Right Decks
MVP Robert L. Bouge

My Sites – Market Yourself!!
MVP Liam Cleary

SharePoint Work Acceleration Toolkit 2007 aka (SWAT)
MVP Pierre Erol GIRAUDY

Favorite CodePlex SharePoint Projects
MVP Bil Simser

Customizing master-detail lists with SharePoint Designer
Searching your SharePoint sites with Internet Explorer 8
MVP Agnes Molnar

How to Implement Governance and Taxonomy™ Planning in SharePoint
Quick and Simple Method to Establish Your Policy Governance Team
Mark Schneider

HOW TO- Enhance SharePoint User Profiles With The Business Data Catalog
MVP Todd Baginski

http://www.21apps.com/category/agile/testing/ (All posts tagged with testing is worth a look!)
MVP Andrew Woody

JQuery - A Fresh Look at What YOU Can Do On SharePoint Without Server Code
Joel Oleson aka. SharePointJoel


Published: Apr-25-09 | 10 Comments | 0 Links to this post

SharePoint Diagnostics Tool (SPDiag) – Released today

Okay, this isn’t a “thought on development” but it’s for sure good news for the admin-guys out there..

Today Microsoft Download Center released a new tool for Administrators and monitoring-people, namely a tool called SPDiag.

Basically, I’ll let the Microsoft Download Center speak for itself;

The SharePoint Diagnostic tool (SPDiag) version 1.0, included with the latest release of the SharePoint Administration Toolkit, was created to simplify and standardize troubleshooting of SharePoint Products and Technologies, and to provide a unified view of collected data. SharePoint Products and Technologies administrators can use SPDiag to gather relevant information from a farm, display the results in a meaningful way, identify performance issues, and export the collected data and reports for analysis by Microsoft support personnel.

Documentation

The overview and documentation of the tool can be downloaded here:

http://www.microsoft.com/downloads/details.aspx?familyid=1c222804-51c7-4bb5-ae3d-89c68ad27a78&displaylang=en&tm

Download

The tool is bundled with the latest release of the SharePoint Administration Toolkit which you can search for here (depending on what version you want (x86/x64):

http://www.microsoft.com/downloads/results.aspx?pocId=&freetext=SharePoint%20Administration%20Toolkit&DisplayLang=en#

Update/Edit 2009-02-05

Microsoft just released the v3.0 version of the SharePoint Administration Toolkit. Use the link above and you’ll see it in the search results.

Cheers!


Published: Feb-04-09 | 6 Comments | 0 Links to this post

How To: SharePoint and Silverlight 2.0 – Part 1

Author: [MVP] Tobias Zimmergren
Web: http://www.zimmergren.net

Prephase

I have previously written up a few articles on how you can get more from your SharePoint environment by enhancing it with AJAX, .NET 3.5 and Silverlight.

References to those articles can be found here:

My intention is to get a SharePoint / Silverlight article series going, and this is to be the first article in the series – How to get up and running!

Prerequisits

Must have:

Note: I’m not going to describe how you create a .xap file – you’ll find plenty of resources for that on the net. Just go google! (Live.com, yeah!)

Nice to have:

Part 1 – Step by step to configure your SharePoint environment for Silverlight 2.0

First of all, if you don’t want to do the manual .NET 3.5 settings in your web.config – there’s a great feature to take care of this on CodePlex which can be found under the Features project.

Step 1: Download, install and deploy the .NET 3.5 Web Config feature
  • Download the .NET 3.5 web.config feature from here
  • Install the .wsp into your SharePoint environment
  • Deploy the .wsp into your SharePoint environment to the appropriate Web Application
    image
  • Activate the feature for your Web Application (the one you deployed to)
    (This is done from Central Administration – Application Management – Manage Web Application Features)
    image 

Now we’re all set with the pre-configurations of the web.config – though there’s one more thing we need to manually do.

Step 2: Adding the final touches to web.config manually

Since the features project doesn’t include Silverlight by default (except for the Beta 2 version, which we’re not interested in..) you should now open up your web.config manually and

  • add the following line to <system.web> <compilation> <assemblies>:

<add assembly="System.Web.Silverlight,
    Version=2.0.5.0,
    Culture=neutral,
    PublicKeyToken=31bf3856ad364e35" />

It should look something like this:
image

Step 3: Add System.Web.Silverlight.dll to the GAC (Global Assembly Cache)

Add the System.Web.Silverlight.dll to the Global Assembly Cache (either drag’n’drop it into C:\Windows\assembly or use Gacutil.exe or use the default .NET Configuration Tool)

You’ll find the System.Web.Silverlight.dll assembly in the Silverlight 2.0 SDK folder, located here:

C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Server\

Step 4: Set the correct MIME-type for the Silverlight .xap filetype

Go to your IIS management console (Start – Run - “inetmgr” without the quotes)

  • Select your Web Application from the list, and select properties:
    image
  • Choose “HTTP Headers” and then “MIME Types…”
    image
  • Add the MIME-type for Silverlight 2.0 Applications as shown:
    image
  • Okay, Okay, Okay (Press the buttons..)
  • Close the IIS manager as we will not need it anymore for the time being!

Now when all those fancy-pancy things are done – let’s get rolling with creating a simple Hello World Web Part using Silverlight 2.0, shall we?

Part 2 – Creating a first Web Part to host a Silverlight application

If you’ve read this far you should now be set up properly to create a Silverlight Web Part (Really, a Web part that loads the silverlight application and renders in the browser)

Step 1: Visual Studio 2008 time!

First of all, make sure you’ve got the .xap file in handy, then launch Visual Studio 2008 SP1.

  • Create a new Web Part project in your desired fashion – I’m using the WSS Extensions for ease:
    image
  • Add a reference to the System.Web.Silverlight assembly and to the System.Web.Extensions assembly, it should look something like this:
    image
     
  • Add the following using statements:
    Note: I’ve stripped down the default using statements, as they’re overkill for this – this is what you should need

    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.SilverlightControls;


  • Make an override on the OnInit method (We will dynamically add a ScriptManager to the current page, if there’s not one already):

    protected override void OnInit(System.EventArgs e)
    {
        base.OnInit(e);
        var sm = ScriptManager.GetCurrent(Page);
        if(sm == null)
        {
            var scriptManager = new ScriptManager();
            scriptManager.EnablePartialRendering = true;
            Page.Form.Controls.AddAt(0,scriptManager);
        }
    }

  • Write the following very simple code to load a Silverlight class into the Web Part, set it’s source to our .xap file and simply add it to the controls collection:  

    private Silverlight mySLControl;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        mySLControl = new Silverlight
        {
            ID = "HelloSilverlightControl",
            Width = new Unit(367), 
            Height = new Unit(150),
            Source = @"/_layouts/ZimmerLight/Hello/Hello.xap"
        };
        Controls.Add(mySLControl);
    }

  • Build and deploy the Web Part, and cross your fingers!
    (Using the WSS Extensions for Visual Studio, just rightclick the project and choose Deploy)
    image 
Step 2: Add the Web Part to a page
  • I’ve put my Web Part in a “Silverlight Web Parts” group – simply choose it and click add.
    image 
  • Voila, a fully functional Silverlight 2.0 Web Part rendered inside SharePoint – without any trouble!
    image


Summary and Download

As you’ve seen in this article, it isn’t too hard to get up and running with Silverlight 2.0 (and .NET 3.5 of course) and get our first Silverlight 2.0 Web Part spinning in SharePoint.

You should now be able to:

  • Configure your environment to use Silverlight 2.0
  • Hook up your Silverlight Application(s) in SharePoint
  • Enjoy the richness of Silverlight in SharePoint!

You can download the Visual Studio project from here

Comments and Feedback appreciated

Please leave your print in the comments, feedback is always nice :-)


Published: Dec-10-08 | 23 Comments | 0 Links to this post

CKS EBE – Comments Manager

Introduction

<EDIT>
    A new version of this tool can be downloaded [here]
    Read more about the new version [here]
</EDIT>

I have been getting a few requests from people who've been getting quite a lot of spam in their Enhanced Blog Edition SharePoint blog, and who don’t currently have the ability to change any code or make adjustments. (They’ve got permissions to the system, but not to actually do anything like upgrade the assembly, add a nifty re-captcha validator or any other changes. They’re only allowed to do the “admin-stuff through the admin-interface”).

My quick and dirty solution was to provide them with a “Comments Manager” which basically is a Windows Application that will list all comments in the blog with a checkbox beside it. The “admin” can then check the desired (or, undesired..) blog comments and then kill them. This solution proved to be much faster than to do the same using the web browser using e.g. the tedious “Edit in datasheet view” option.

Note; This isn’t by far any cool application – it merely does what the few people want it to do, kill undesired comments with a better overview :)

Features

This light-weight application will do the following:

  • List all comments
    • Comment Author
    • Trimmed Body
    • Background-coloring
      • Green for comments with status = “Approved”
      • Red for all other (Rejected and Pending)
  • Kill selected comments

Simple as that!

Comments Manager preview

image

Download

Download the CKS:EBE Comments Manager v1.1.0.0

If you have ideas or comments, or if it simply doesn’t work – leave a comment!
Better yet, leave a comment anyway! :)

Future additions

If required by the people using this simple app – the future versions could include

  • Comment status change [Approval status]
  • Use Web Services to connect to your SP site instead
  • Track- and linkback manager
  • etc. etc.


Published: Oct-16-08 | 4 Comments | 0 Links to this post

Web Part Caching – A simple approach

All kudos to Vince Rothwell who provided an awesome blogpost on SharePoint Caching and the CacheDependency object

This week I am tutoring a SharePoint 2007 development class over at Informator in Gothenburg, Sweden. Today we’ve been looking at Web Parts, creation of custom webparts and best practices for creating our custom solutions based on web parts.

I quickly coded up a sample which is caching items in a webpart - Huge server load is a major impact point for some organizations, making caching a strategically important choice if there’s much redundancy.

Anyway, you probably already know that it’s a good thing to cache your data once in a while if you’ve got heavy load and the data isn’t any “to-the-minute” critical information. So let’s get on with it..

Why?

Since people have been asking for a ‘simple sample’ of how to cache things in SharePoint – I thought that I would provide just that, a simple sample. For more in-depth information about caching and cachedependendies, check out Vince’s blog.

Check it out!

Web Part fetching items from a SPWeb object, looping all SPList objects and displaying the ItemCount property.

If there isn’t a cache object present, the iteration of the lists will be done immediately
image

If there is a cache object present, it will fetch the information from the cached object instead of iterating the lists, saving us some resources 
image

Code It!

This is the full code of the simple sample cache Web Part:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Microsoft.SharePoint;
using System.Web;
namespace Zimmergren.WebParts.SampleCachePart
{
    public class SimpleCache : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer); 

            List<SPList> lists = new List<SPList>();
            string status = ""; 

            if (HttpRuntime.Cache["SimpleSampleCache"] == null)
            {
                status = "The following items are <strong>NOT</strong> fetched from the cache<br/><br/>"; 

                SPWeb web = SPContext.Current.Web;
                foreach (SPList list in web.Lists)
                    lists.Add(list); 

                HttpRuntime.Cache.Add("SimpleSampleCache",
                lists,
                null,
                DateTime.MaxValue,
                TimeSpan.FromMinutes(10),
                System.Web.Caching.CacheItemPriority.Default, null);
            }
            else
            {
                status = "The following items <strong>ARE</strong> fetched from the cache!<br/><br/>";
                lists = (List<SPList>)HttpRuntime.Cache["SimpleSampleCache"];
            } 

            writer.Write(status);
            foreach (SPList l in lists)
                writer.WriteLine(l.Title + " - " + l.ItemCount + " items<br/>");
        } 
    }
}

Summary & Download!

I always use the HttpRuntime or HttpContext objects to store and read my cached objects. You can of course use the built-in caching functionality of WSS 3.0 Web Parts if you feel that you have the need for it. However this approach works everytime, everywhere. Not just for Web Parts of course, but for any kind of ASP.NET hooked application.

You can download the sample project [here]

Thanks for tuning in,
Cheers


Published: Oct-07-08 | 11 Comments | 0 Links to this post

How to: LINQ with SharePoint - .NET 3.5 Framework with SharePoint Part 2

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 :-)


Published: Sep-28-08 | 15 Comments | 0 Links to this post

How to: Get up and running with .NET 3.5 in your SharePoint environment

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


Published: Sep-22-08 | 27 Comments | 0 Links to this post
 Next >>