Author Archive

SharePoint 2010 sneak peek

Tuesday, July 14th, 2009

Finally Microsoft released some info on the new features for SharePoint 2010.

Though these are not all the features that are going to be in the new version, it certainly sounds promising!

Source: http://officesharepointpro.com/Articles/tabid/149/nodeid/1982/The-Curtain-Rises-(Just-a-Bit)-on-SharePoint-2010.aspx

SPList.Views does not retrieve hidden views

Monday, July 6th, 2009

Last week I created a list definition with a couple of hidden Views in it, which would only be used in list view webparts.

The Views were defined like this:

 <View BaseViewID="101" Hidden="TRUE" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="FALSE" SetupPath="pagesviewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems_Hidden.aspx">

One of these webparts had to be added programmatically with only the BaseViewID (int) as a reference (101 in the above case).

Now, my normal approach would be to retrieve all views from the list by using SPList.Views and loop trough these views untill I come across the BaseViewID I am looking for.

HOWEVER… When looking in the SPViewCollection retrieved by SPList.Views, the hidden views are nowhere to be found!

Eventually, I found out that we can use the SPList.GetUncustomizedViewByBaseId(int) method, and then get the ViewID out of the PropertiesXml property.

I did it like this:

private Guid GetListViewID(SPList list, string baseViewID)

{

    string properties = list.GetUncustomizedViewByBaseViewId(Convert.ToInt32(baseViewID)).PropertiesXml;

 

    XmlDocument doc = new XmlDocument();

    doc.LoadXml(properties);

 

    Guid listViewId = Guid.Empty;

    string viewUrl = doc.FirstChild.Attributes["Url"] != null ? doc.FirstChild.Attributes["Url"].Value : "";

    if (!string.IsNullOrEmpty(viewUrl))

        listViewId = list.ParentWeb.GetViewFromUrl(string.Format("{0}/{1}", list.RootFolder.Url, viewUrl)).ID;

 

    return listViewId;

}

I don't know if anyone else had encountered this issue, but it seems like something strange to me :)

Maybe I defined my hidden view in an incorrect way, or maybe there is some property or method I overlooked, I don't know.

Anyway, this solution seems to work for me to :) so I hope it helped someone else to ;)

ListInstance and “Object reference not set to an instance of an object”

Wednesday, April 29th, 2009

I had some trouble with a ListInstance feature today, which was activated through a custom site definition. This resulted in quite some frustration, so I was glad to finally find the solution.

Thanks to the blog post on http://sigurbjorn.wordpress.com/2008/07/21/listinstance-and-object-reference-not-set-to-an-instance-of-an-object, It got solved. Thanks Sigurbjörn !

Description
While activating a feature that contains list instances I get an “Unknown error” message in the SharePoint UI.

Log Entry
The element ‘NameOfListInstance’ of type ‘ListInstance’ for feature ‘MyCompany.SharePoint’ (id: 00000000-0000-0000-0000-000000000000) threw an exception during activation: Object reference not set to an instance of an object.

My solution
After a lot of debugging I noticed that if I remove the RootWebOnly=”TRUE” attribute from the ListInstance element the error goes away.

Adding a content editor webpart to a site definition

Wednesday, March 11th, 2009

I was trying to add a content editor webpart, with content of course, to a site definition. However, it took me to much searching to get to the right solution :) So I thought I'd write a little post about it :)

To add the webpart, add an AllUsersWebPart in a <Module>/<File> tag:

        <AllUsersWebPart WebPartZoneID="Left" WebPartOrder="0">

          <![CDATA[

            <WebPart

              xmlns="http://schemas.microsoft.com/WebPart/v2"

              xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor">

              <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

              <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>

              <Title>Working with Site Definitions</Title>

              <FrameType>None</FrameType>

              <cewp:Content>

                &lt;h2&gt;Welcome to SharePoint&lt;/h2&gt;

                &lt;p&gt;Use this website to store documents and keep lists of information.&lt;/p&gt;

              </cewp:Content>

            </WebPart>

          ]]>

        </AllUsersWebPart>

Also, don't forget to strip your HTML tags from < to &lt; and > to &gt;

Add WSP Solutions through the interface

Monday, January 12th, 2009

One of the things I always missed in SharePoint is the fact that WSP solutions always had to be added through STSADM, and could not be added through the Solution management page …

So, I created a solution myself which adds a toolbar to the page, which allows to do exectly that.

It's been done by creating a custom solutions.aspx page (CustomSolutions.aspx), and adding a HttpModule to the web.config of the Central Administrator web application.

The pages ended up to look like this:

CustomSolutions.aspx
 

AddSolution.aspx 

 The WSP and source code both can be found on Codeplex.

Automatic removal of lists when deactivating ListInstance feature

Thursday, November 20th, 2008

Creating lists using ListInstances is quite easy to do within a feature. However, deleting those lists again when deactivating that feature does not happen automatically (which is understandable, since you don't want to lose all data in the list when accidentally deactivating the feature …).

So, I created a feature receiver to do the job for you :) The receiver simple deletes all lists created by a ListInstance tag in the feature.

This is how I did it:

1. The feature.xml file

<?xml version="1.0" encoding="utf-8" ?>

<Feature xmlns="http://schemas.microsoft.com/sharepoint/"

         DefaultResourceFile="blog"

         Id="{40B0BD50-8A65-4cc3-99E4-28024DA1A487}"

         Title="Blogging list instances"

         Description="This feature enables the custom list instance definitions."

         Version="1.0.0.0"

         Scope="Web"

         ReceiverAssembly="SharePoint.Blogging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bc158afeef6140c2"

         ReceiverClass="SharePoint.Blogging.ListInstanceRemover">

  <ElementManifests>

    <ElementManifest Location="Elements.xml"/>

  </ElementManifests>

</Feature>

Notice that I set the DefaultResourceFile property to a self-created resource file, which is deployed in the 12/Resources folder.

2. The elements.xml file

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <ListInstance Id="0"

                Description="A test list for the blogging article."

                FeatureId="{00BFEA71-DE22-43B2-A848-C05709900100}"

                OnQuickLaunch="TRUE"

                QuickLaunchUrl="/BlogList/AllItems.aspx"

                TemplateType="100"

                Title="$Resources:ListInstances_List_Title"

                Url="BlogList" />

  <ListInstance Id="1"

                Description="A test document library for the blogging article."

                FeatureId="{00BFEA71-E717-4E80-AA17-D0C71B360101}"

                OnQuickLaunch="TRUE"

                QuickLaunchUrl="/BlogDocLib/Forms/AllItems.aspx"

                TemplateType="101"

                Title="$Resources:blog,ListInstances_DocLib_Title;"

                Url="BlogDocLib" />

</Elements>

3. The feature receiver (the important part)

To create a feature receiver, we create a class overriding SPFeatureReceiver.

using System;


using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

using Microsoft.SharePoint.Utilities;

using System.Globalization;


namespace SharePoint.Blogging

{

    public class ListInstanceRemover : SPFeatureReceiver

    {

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

        {

            CultureInfo ci = System.Globalization.CultureInfo.InvariantCulture;

            SPElementDefinitionCollection elementFiles = properties.Definition.GetElementDefinitions(ci);


            foreach (SPElementDefinition elementFile in elementFiles)

            {

                if (elementFile.ElementType == "ListInstance")

               {

                    string defaultResourceFile = properties.Feature.Definition.DefaultResourceFile;

                    string listTitle = SPUtility.GetLocalizedString(elementFile.XmlDefinition.Attributes["Title"].Value, defaultResourceFile, Convert.ToUInt32(ci.LCID));


                    SPWeb web = properties.Feature.Parent as SPWeb;

                    SPList list = web.Lists[listTitle];


                    list.Delete();

                }

            }

        }

        public override void FeatureActivated(SPFeatureReceiverProperties properties)

        {

        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)

        {

        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)

        {

        }

    }

}

You might also notice me using the SPUtility.GetLocalizedString method, which actually is very handy to use when dealing with resource files, as it translates the resource string into the localized value.

There, that's it. I hope it helps someone in some way … ;)

Webpart's Summary Toolbar view in list definition

Friday, October 31st, 2008

I created a list from a custom list definition, and wanted to add the list as a webpart to a page defined in my custom site definition.

In the sitedefinition, it was enough to declare the BaseViewID property to define which view I wanted the list to display on the webpart.

<View List="Lists/LinksDocLibs" BaseViewID="4" WebPartZoneID="Left" WebPartOrder="2" />

Then, in the list definition, I modified my selected view to show the FreeForm toolbar, which should only display the "Add new item" link underneath the webpart.

<Toolbar Type="FreeForm" Position="After" />

However, when using this, the "Add new item" link is not shown. To accomplish this, we have to insert some HTML into the <Toolbar> tag. Do it like this:

<Toolbar Type="FreeForm" Position="After">

  <IfHasRights>

    <RightsChoices>

      <RightsGroup PermAddListItems="required"/>

    </RightsChoices>

    <Then>

      <HTML>

        <![CDATA[<table width=100% cellpadding="0" cellspacing="0" border="0">

        <tr><td colspan="2" class="ms-partline"><img src="/_layouts/images/blank.gif" width="1" height="1" alt=""></td></tr>

        <tr><td class="ms-addnew" style="padding-bottom:3px"><img src="/layouts/images/rect.gif" alt="">

        &nbsp;<a class="ms-addnew" ID="idAddNewItem" href="]]>

      </HTML>

      <URL Cmd="New"/>

      <HTML>

        <![CDATA[" onclick="NewItem(']]>

      </HTML>

      <URL Cmd="New"/>

      <HTML>

        <![CDATA[',true);return false;" target="_self">]]>

      </HTML>

      <HTML>

        Add a new item

      </HTML>

      <HTML>

        <![CDATA[</a></td></tr><tr><td><IMG src="/_layouts/images/blank.gif" width=1 height=5 alt=""></td></tr></table>]]>

      </HTML>

    </Then>

  </IfHasRights>

</Toolbar>

There, that should do the trick :)

Starting with this, you can also easily customize your layout as you can change the entire HTML markup for the Toolbar template ;)

Have fun with it ;)

 

Thanks to Tippu for the inspiration in this post.

STSADM Extensions on CodePlex

Sunday, October 19th, 2008

Last friday I opened a project on CodePlex, in which I, together with some collegues, am going to put some stsadm extensions which are, or seem to be, usefull to us.

If you have any recommendations or ideas to put in them, please leave a comment over there, or in this blog.

You can find the project at http://www.codeplex.com/stsadmextensions

The first functionality I added is "resetapplicationpool", by which you can reset the app pool of a site of which you have to specify the url. Thought it might be easier to use than finding the correct one in inetmgr all the time …

32-bit color in remote desktop

Thursday, October 16th, 2008

 I just installed Windows Server 2008 on a VM machine, but was disappointed to see that through a remote connection, it would only show 16-bit colors by default.

I know, I know, it should look good, it should just perform well. But still, I wanted to use 32-bit colors when running the server (I mean, even the trashcan icon looked awefull :p)

Now, I did some searching and found the reason that 32bit was not in de choice list in display settings, so here it is:

On your host, do the following:

1. Run GPEDIT.MSC;
2. Go to: Local Computer Policy/Computer Configuration/Administrative Templates/Windows Components/Terminal Services/Terminal Server/Remote Session Environment;
3. Open the policy 'Limit maximum color depth';
4. Set this to Disabled or Enabled (with 32-bit selected under it then)

 

I know this isn't the most important setting in Windows Server :) but it does look better now :p

SharePoint content types inheritance fixed

Tuesday, October 14th, 2008

I came across a great post from Martin Hatch today, which provides a solution for problems with content types and list definitions in features.

I tested it and it seems to work great, although i did make a little change, since the handler throws an error when using a RemoveFieldRef node in the CT definition.

So, i changed this: 

foreach (XmlNode fieldRef in node.ChildNodes)

{

    #region Loop through FieldRefs

    //ignore XML comment tags

    if (fieldRef.Name == "#comment")

    {

       continue;

    }

    string fieldID = fieldRef.Attributes["ID"].Value;

    SPField field = cType.Fields[new Guid(fieldID)];

    cType.FieldLinks.Delete(new Guid(fieldID));

    cType.Update(true);

    cType.FieldLinks.Add(new SPFieldLink(field));

    cType.Update(true);

    #endregion

}

to this:

foreach (XmlNode fieldRef in node.ChildNodes)

{

    #region Loop through FieldRefs

    //ignore everything but FieldRefs

    if (fieldRef.Name == "FieldRefs")

    {

        string fieldID = fieldRef.Attributes["ID"].Value;

        SPField field = cType.Fields[new Guid(fieldID)];

        cType.FieldLinks.Delete(new Guid(fieldID));

        cType.Update(true);

        cType.FieldLinks.Add(new SPFieldLink(field));

        cType.Update(true);

    }

    #endregion

}

Seems to work to me, but if anyone has another suggestion :) please do let me know ;)