Custom list definitions with custom forms – changing master page

[Tiny post]

As many of you might have experienced when you create your own custom list definition, you can also create your custom forms (DispForm.aspx for example).

In my case, I want the DispForm.aspx to use another master page than it originally does, and so I thought I’d just change the following line of my DispForm.aspx:

From:

<%@ Page language="C#" MasterPageFile="~masterurl/default.master" …%>

To:

<%@ Page language="C#" MasterPageFile="~/_layouts/zTest/test.master" …%>

Problem

Doing this will most likely cause you to receive the following known error message:

An error occurred during the processing of . The referenced file '/_layouts/zTest/test.master' is not allowed on this page.

Solution/Workaround

Instead of changing the MasterPageFile attribute of the Page directive, inject some server-side script in the DispForm.aspx in order to change the MasterPageFile property though code.

In your DispForm.aspx, do the following:

  • Keep the MasterPageFile=”~masterurl/default.master” attribute
  • Insert the following server-side script directly undet the <%@ Page … %> directive:

<script runat="server">
    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.MasterPageFile = "~/_layouts/zTest/test.master";
    }
</script>

  • Watch your DispForm.aspx use a new Master Page without getting the error message.

Thanks to

I’d like to shout out to MVP Eric Schupps for giving me this smart tip.
I just might buy you a beer, Eric.


Published: Jan-05-09 | 0 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 | 14 Comments | 0 Links to this post

How To: Custom Web Part Properties (ToolPart)

I’ve been getting a few requests from people who basically want to know how you can modify the Web Part Properties window – and foremost add your own logic and controls there.

Prerequisites

  • SharePoint 101 basic knowledge
  • Knowledge about how you build and deploy Web Parts in SharePoint
  • (Really, you can just download the entire project in the end of this article and skip the pre-reqs.)

Intro

I will walk you through how you can add your own custom controls in the Web Part property pane, instead of relying on the standard controls.

Sometimes you’re just required to have a bit more advanced controls put in place which the default functionality can’t deliver. That’s where the ToolPart comes in handy!

In this case the ToolPart will do a lookup and see what Lists (SPListCollection) exists on the current site, and populate a simple DropDownList with the values.

Important note
I havn’t fully implemented the properties etc. in this Web Part in a manner you would preferbly do it – I’m simply focusing on the topic of the custom toolpart.

Overview

Default property pane (in this case, ListViewWebPart for Contacts)
image

Custom ToolPart pane with custom logic for the controls
image

Example of using the Web Part properties in the Web Part
image

Walkthrough

  • Launch Visual Studio (2008 in my case)
  • Create a new Web Part in your preferred way (I actually used the Extensions for WSS for once..)
  • WebPart1.cs Add the properties you want to your webpart
  • public string Property1
    {
         get
         {
             return _property1;
         }
         set
         {
             _property1 = value;
         }
    }
    string _property1;
    public string Property2
    {
         get
         {
             return _property2;
         }
         set
         {
             _property2 = value;
         }
    }
    string _property2;

  • WebPart1.cs Override the Render()-method in order to simply output the properties we just created
  • protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        writer.Write(Property1);
        writer.Write("<br/>");
        writer.Write(Property2);
    }

  • WebPart1.cs Override the GetToolParts()-method in order to alter the toolpane
  • public override ToolPart[] GetToolParts()
    {
        ToolPart[] allToolParts = new ToolPart[3];
        WebPartToolPart standardToolParts = new WebPartToolPart();
        CustomPropertyToolPart customToolParts = new CustomPropertyToolPart(); 

        allToolParts[0] = standardToolParts;
        allToolParts[1] = customToolParts;
        allToolParts[2] = new CustomToolPart(); 

        return allToolParts;
    }

What we’re doing here is firstly instantiating the WebPartToolPart class which gives us the standard toolpart. Next we’re adding the CustompropertyToolPart which adds a custom property toolpart. Finally we’re adding our CustomToolPart to the collection of ToolParts and then we’re returning the collection – telling SharePoint that this is how we want it to render!

  • CustomToolPart.cs Create a new class called CustomToolPart and derive from Microsoft.SharePoint.WebPartPages.ToolPart
  • public class CustomToolPart : Microsoft.SharePoint.WebPartPages.ToolPart
    {
            DropDownList ddl;
            Panel toolPartPanel;
            TextBox tb; 

            protected override void CreateChildControls()
            {
                toolPartPanel = new Panel();
                ddl = new DropDownList();
                ddl.ID = "ddl"; 

                // Simply getting the lists of the current web, and displaying them in the dropdown-list.
                SPListCollection lists = SPContext.Current.Web.Lists;
                foreach (SPList list in lists)
                    ddl.Items.Add(list.Title);

                tb = new TextBox();
                tb.ID = "tb"; 

                toolPartPanel.Controls.Add(ddl);
                toolPartPanel.Controls.Add(tb);
                Controls.Add(toolPartPanel);
                base.CreateChildControls();
            } 

            public override void ApplyChanges()
            {
                WebPart1 wp = (WebPart1)this.ParentToolPane.SelectedWebPart;
                wp.Property1 = ddl.SelectedValue;
                wp.Property2 = tb.Text;
            }
    }

The only noteworthy thing in this class is the override of ApplyChanges which basically tells our WebPart (this.PartenToolPane.SelectedWebPart is WebPart1) that it should set it’s properties to the values in the custom property toolpart we’ve created.

Summary & Download

That was easy enough – this was just a really swift intro to how you can manage your own controls and behaviour for your webparts properties.

You may download the VS2008 project here.

Enjoy


Published: Nov-29-08 | 6 Comments | 0 Links to this post

I can (Windows) Azure you – Song

Okay, so I’ve been writing up a simple song the last week, which I just recorded with my laptop-microphone at the same time that I tried to do some tricks with the guitar… It all ended up with a song called “I can (Windows) Azure you”.

You can download the song here

Being a serious guy and all, please don’t take the song too serious ;-)

However! You may do cool remixes if you’d like, just let me know because they couldn’t possibly get any worse than this! :-)

Have a good weekend all!

Enjoy.


Published: Nov-28-08 | 15 Comments | 1 Link to this post

Sweden SharePoint User Group presentations

You’ll find the presentations from the UG meeting here;

I’m still waiting for access to the site from Daniel. Before I get that access I’m afraid I can’t do any real admin-stuff as we’ve discussed..

For any issues, questions, proposals, ideas or other thoughts regarding the User Group – mail me using the contactform under “contact”.

Cheers


Published: Nov-26-08 | 5 Comments | 0 Links to this post

Sweden SharePoint User Group – First meeting done

We had our first meeting this tuesday (November 18th) with about 30 people showing up. The interest is growing for the group, and as it looks now there’ll be more people coming to the next set of meetings. Fun!

Thanks to everyone who contributed to the meeting taking place.

In the picture I’m doing a presentation on what’s new and hot in the SharePoint world. And it looks like I’m trying to fly out from there with my left arm…
DSC00080

All in all, it was a great evening!

Hope to see you around!

Z


Published: Nov-20-08 | 5 Comments | 0 Links to this post

Microsoft Office Systems 2007 – Service Pack 2

Recent announcements around the blog-o-sphere and the announcements at TechEd in Barcelona indicated that the SP2 for Office Systems 2007 is on it’s way.

Releasedates

Don’t even bother to try to get an exact date for your upgrade. As it is said today, the SP2 for Microsoft Office Systems 2007 will be released somewhere between February and April 2009.
If you are to take SP2 into consideration, I would go for the latter timescope (April/May) to be sure :-)

Clients

As announced by the Office Service Pack Team:

Improved Outlook Calendaring Reliability

Improved Outlook Performance

Enabling Object Model support for Charts in PowerPoint and Word

Improved cryptographic functionality by supporting all cryptographic algorithms offered by the operating system

Improved functionality in Excel’s charting mechanism

Ability to ungroup SmartArt graphics (and as a result, the ability to add animations to them in PowerPoint)

Ability for Visio to export UML models to an XML file compliant with the XMI standard

Tool that enables the uninstall of Office client Service Packs

Servers

As per the Microsoft SharePoint Team Blog, the following parts are some of the SharePoint-related things that will be taken care of:

Improved Read-only Content Databases
Whenever a content database is marked read-only, all of the site collections in that database are automatically marked as read-only. 

ECM Performance and Manageability Improvements
Improved performance and manageability in variations, including STSADM commands for repairing links between source and target pages.

Improved Index Rebuild Timer Jobs
SharePoint content databases running in SQL Server 2005 will undergo an automatic index rebuild, which helps stop defragmentation, and stop the database from degrading in performance.

Upgrade Checker
This will scan your SharePoint farm in advance of applying SP2 and will provide feedback on the environments readiness to upgrade.

Summary

I do hope to see some more in-depth details as to what exact improvements are being made regarding the read-only content databases!

Regarding the Upgrade Checker, I think it’s something that should have existed for every SP and KB/Patch you install. Kind of like the “Windows Vista Upgrade Advisor”, but for SharePoint!

More info will be published about SP2 when it’s announced, stay tuned!


Published: Nov-16-08 | 1 Comment | 0 Links to this post

MSDN Ramp Up – Free training online

rampup
If you are looking for some free training within any of the many Microsoft technologies, have a look at MSDN's Ramp Up site. It's a free community-based learning program where you can choose the training that fits your needs.

Ramp Up overview

These are the different tracks you can currently choose from;

SharePoint for developers track – Part 1

Well, foremost since there’s a new “SharePoint for developers” track availible here

rampupsharepointdev1

This is a great way to improve your current skillset by adding some additional SharePoint skills (if you don’t have them already). It’s really easy to make this happen in your own pace.

This is the current set of levels in the SharePoint track part1:

  • Level 1: Web Parts
  • Level 2: Data Lists
  • Level 3: Event Handlers
  • Level 4: Workflow
  • Level 5: Silverlight

Published: Nov-16-08 | 2 Comments | 0 Links to this post

Sweden SharePoint User Group – November 18

We’re going to have our first User Group with Sweden SharePoint User Group on Tuesday, November 18.

Anyone can register and attend the meeting, as long as you sign up here!

I will be presenting some highlights (at least what I found interesting in my SharePointer-eye) from TechEd Developers – which is also a recap of what was said at the PDC conference!

I hope to see you there!

Regards,
Tobias


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

Leaving for TechEd EMEA 2008 – Developers

So, after a few weeks of conferences around the globe (PDC, TechEd) the time has come for the TechEd EMEA 2008 Developer tracks.

I’m leaving for Barcelona in the morning, tomorrow monday, and will arrive during the early noon.

I hope to see some of you guys there, and keep an eye out for updates in my blog!

TechEd_EMEA_180_SeeYouThere_DEV

Cheerio!


Published: Nov-09-08 | 4 Comments | 0 Links to this post
 Next >>

MCTS WSS 3.0 (Developer and Administration/Configuration) MCTS MOSS 2007 (Developer and Administration/Configuration) MCP