My blog has moved!

My blog has moved to http://www.lamber.info. Click on the redirect button below to be redirected to the blog post.

Please update your bookmarks and use the new url for getting new updates.

Pages

Sunday, October 31, 2010

SharePoint 2010: adding, editing, or removing WebParts (content) on Dispform.aspx, Editform.aspx, and NewForm.aspx without SharePoint Designer

Most users benefit from the great browser editing experience of SharePoint 2010. On the other side, SharePoint 2010 Designer is required when making changes to the “Dispform.aspx”, “Editform.aspx”, or “NewForm.aspx” list forms. However, if your requirement is to add, edit, or remove some WebParts (content) to these pages, you don’t necessarily need to launch SharePoint 2010 Designer.

This can be accomplished by changing slightly the URL of the form that you want to edit. You only need to extend the URL with the query string parameters “PageView=SharedView&Toolpaneview=2”.

Here some examples how it will look like:

  • <your host>/Lists/<your list>/dispform.aspx?PageView=SharedView&Toolpaneview=2
  • <your host>/Lists/<your list>/editform.aspx?PageView=SharedView&Toolpaneview=2
  • <your host>/Lists/<your list>/newform.aspx?PageView=SharedView&Toolpaneview=2

When adding these parameters to your desired URL, SharePoint 2010 changes to the page editing mode that you are used to have on other WebPart pages. You can add, edit or remove WebParts to this page.

Please note, however, that changing the list item fields is still not possible in this way. This can be accomplished in SharePoint 2010 Designer or by modifying the visibility parameters of your list content type..

 

Hope this helps,

Patrick

Friday, October 22, 2010

“An unexpected exception has occurred” when associating a reusable workflow to a list or content type in SharePoint 2010 Designer

recently I was creating some reusable workflows for one of my customers with SharePoint 2010 Designer. Once a reusable workflow is created, you can assign it either to a list or a content type in SharePoint 2010 Designer. When you executed one of these steps, however, a browser window opens and redirects you directly to the workflow association page of your list or content type. Normally, you can finish the association process directly there.

Unfortunately, this time I got a very useful “An unexpected exception has occurred” that everyone of us loves.

image

After several trials I found the mistake that I made. My reusable workflow was never published (I only saved it and forgot to publish it) in SharePoint 2010 Designer before. Therefore, the system was not able to assign a workflow that was only saved. Somehow clear, you might think. However, the error message was in this case not very useful.

So don’t forget to publish your workflow with SharePoint Designer before assigning it to a list or a content type!

 

Hope this helps,

Patrick

Saturday, October 16, 2010

File not found exception when accessing SPSite

when you want to build custom application in Visual Studio 2010 that are accessing the SharePoint 2010 object model, you will probably encounter the famous “File not found exception” when accessing an SPSite.This blog post shows you how to avoid this exception and how to setup your console application or ASP.NET web application the right way.

Overview

SharePoint 2010 runs on an x64 environment and supports the .NET Framework 3.5. All custom applications that want to access the SharePoint 2010 object model must follow the same environmental settings and target platform settings, i.e., run in a .NET Framework 3.5 environment and the platform x64 (or at least “Any CPU”). If you create a console application or an ASP.NET web application, Visual Studio 2010 will probably setup your environment for x84 and the .NET Framework 4.0. If you try to access the SharePoint 2010 object model with this configuration, you will encounter an “FileNotFoundException” when accessing the SPSite object.

In this post I’m going to show you how to configure…

  • a console application accessing the SharePoint 2010 object model
  • a web application accessing the SharePoint 2010 object model

Please note that this post assumes that you correctly add the necessary binary files (e.g., Microsoft.SharePoint) for yourself.

Accessing SharePoint 2010 object model with a console application

As already mentioned in the overview section, you have to ensure that your project environment is setup up to use the .NET Framework 3.5 and the platform target x64 (or Any CPU). You can change the settings of your projects by accessing the project properties.

Ensure that the target framework is .NET Framework 3.5 since the .NET Framework 4.0 is not yet supported.

 targetFramework

Specify the target platform to “Any CPU”…

AnyCPU Console

or x64…

Snip64

The “FileNotFoundException” will be gone away if you start debugging your console application again.

Accessing SharePoint object model 2010 with an ASP.NET application

Accessing the SharePoint object model 2010 with an ASP.NET application follows the same strategy as in the console application. You have to configure the target framework to .NET Framework 3.5 and the target platform to x64 or “Any CPU”. You can change the properties in a similar way as we saw before with the console application.

However, you will not get the same development experience since the integrated web server of Visual Studio 2010 (Cassini) does not run in an x64 environment. Because of that, you will get again the “FileNotFoundException” when accessing the SharePoint 2010 object model. You will notice however, that the application runs like a charm when deployed in web server that supports x64 (such as IIS7). This is really a lame situation, since developing like that can become a pain in the ass.

Don’t worry! We don’t need necessarily to stick on the integrated web server of Visual Studio 2010. We can change our ASP.NET project configuration to be debuggable in an external web server such as IIS7. To do so, we need to follow these steps:

  • configure your web application in Visual Studio 2010 to the target .NET Framework 3.5 and to run as x64 or “Any CPU” (similar as before with the console application)
  • create a web application in IIS7 and configure the application pool to run for the .NET Framework Version v2.0 and x64. To ensure that the application runs in x64, just set “Enable 32-Bit Applications” to false.AppliCationPool
  • configure your web application in Visual Studio 2010 in the property page to “Use Custom Web Server” and specify there the url of your web application in IIS7

targetWeb

  • publish the .NET web application to the target web application of IIS7
  • debug your web application

After setting up the environment like that, after pressing the F5 button, Visual studio 2010 will automatically attach the debugger to the right IIS7 worker process. Now, you are ready to debug your ASP.NET web application without any problems.

Summary

Using the SharePoint 2010 object model in Visual Studio 2010 requires some configuration steps for your custom applications. This post showed you which settings are important to start with for console application projects and for ASP.NET web application projects.

 

Hope this helps,

Patrick Lamber