Archive

Archive for the ‘Sharepoint’ Category

Sharepoint Versioning – Gotcha 2

June 10th, 2009 No comments

I’ve had a right game with this Sharepoint Versioning problem.

Now those of you used to writing .NET but maybe not SharePoint will be used to having AssemblyVersion attributes set in the AssemblyInfo.cs files.

This is something I took into my last SharePoint application for wss3.  Now in SharePoint 2003 I got used to not setting the version number but it slipped my mind for WSS 3.0.

My particular problem was I had some ItemAdding/Updating List events.  These were configured to fire in one of my Assemblies. My build server would automatically increment version numbers in AssemblyInfo.cs and in all associated .xml files in the features, very clever I thought at the time.  Now I needed to update this assembly and modify some code in these events.

I made those changes and installed it and all of a sudden none of the events were firing at all.

This is because when a list is created the EventReceiver details of the feature are not read from the XML file but are stored against the List in the content database.  This makes some sense as if you update the list template then you can update the EventReceivers as well and have different versions of a list definition with different handlers.

In my experience it’s more likely that you will want to modify all the existing lists and template as your probably implementing a fix, especially if using SharePoint as an app platform.

So how to fix my now rogue ItemReceivers.  I could do some fancy coding in Feature activations etc, but I really don’t want to go there and have code left lying about for what will essentially be a one time fix.

To the rescue PowerShell.  Luckily for me we use PowerShell so I  can create a post update installation script that runs just this once.

Here is the gist of it.

###############################################################
# Validate args
###############################################################

    if ($args.Length -ne 1 -or $args[0] -eq "-?")
    {
        Write-Host "Usage: .\FixIt.ps1 <SiteUrl>";
        return;
    }
    $SiteUrl = $args[0];
    cls

###############################################################
#Get Base Objects
###############################################################

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $site = New-Object Microsoft.SharePoint.SPSite $SiteUrl
    $web = $site.RootWeb
    $lists=$web.Lists

###############################################################
#Change List Event Receivers
###############################################################

$list=$lists["BrokenList"]

#I happen to know there are only 4 Receivers really I should use the count
#One of them is named wrong as well hence the 3 cases
#(in the real version I fixed that too)
#You need to count backwards as it deletes and re-inserts so a foreach wont #work.

for ($i=3;$i -ge 0;$i–)
{
    $er=$list.EventReceivers[$i]
    switch($er.Name)
    {
        "BinaryJam BrokenList Receiver ItemUpdating"
        { 
            $er.Assembly="BinaryJam.MySharePointApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111"
            $er.Update()
        }
        "BinaryJam BrokenList Receiver ItemAdded"
        {
            $er.Assembly="BinaryJam.MySharePointApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111"
            $er.Update()
        }
        "BinaryJam BrokenList Receiver ItemAdding"
        {
            $er.Assembly="BinaryJam.MySharePointApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111"
            $er.Update()
        }
    }
}

$list.Update()

 

Categories: development, Sharepoint Tags:

SPUtility.SendEmail Function truncates text

February 10th, 2009 No comments

It would appear that

SPUtility.SendEmail function truncates the body of the email.   I’m having this problem and so is someone else (here).

Not much more to add here, if anyone knows why or knows of a setting, love to here it

(please don’t post a workaround solution using .Net objects we can all figure that one out for ourselves thanks.)

Word of the day.

Damn.

Technorati Tags: ,
Categories: Sharepoint Tags:

WSS – CAML and XSD schemas

February 10th, 2009 No comments

If you developing List Schemas drop what your doing and go and install this.

CAML.NET.Intellisense

It is an expanded wss.xsd file containing a lot of descriptions and possible default values. When coding in Visual Studio using this will alter the schema defs and give you uber intellisense on your schema files.

If you already use wss.xsd in Visual Studio you will need to remove your reference.

Now if you forgot how you did that then the usual way I found of configuring it was to goto

C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas

(or equivalent for your platform)

An to create a file called wsscatalog.xml, you may have called it something else but it contains xml like this

   1: <SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
   2:   <Schema href="%CommonProgramFiles%/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd"
   3:           targetNamespace="http://schemas.microsoft.com/sharepoint/" />
   4: </SchemaCatalog>

 

So go and remove that before installing this version as it won’t remove it for you and Studio can fight over things if you don’t or just not work at all as was my case.

Categories: Sharepoint Tags:

WSS – ListView / Schema.xml and Embedding Javascript

February 9th, 2009 No comments

Many of you out there in SharePoint land will from time to time have the need to edit a list definitions schema.xml file to create your custom list.  You may also have need to edit the List View in that schema file to create a different kind of view, one not possible to create by the SharePoint UI.

I have had need to do this recently.  I needed a List View that highlighted expired items or tickets in my list.  It needed to make them go red.

Now you might think that’s easy enough create a calculated field that does date maths on the date you have in the list item and the current date that gives basically 1 or 0 for expired or not.  Well you’d be wrong.  You see you can’t use [Today] or anything like it in a calculated field the list wants fixed not dynamic values in it and will not allow Dynamic values, think about it, it would seriously effect performance.

Rather than create a DataViewWebPart based on my list view and edit that to death, it did not give me exactly what I required, even with editing, and the time to do it would be longer for me to achieve.  I decided to embed Javascript code into my ListView.

Read more…

Categories: Sharepoint Tags:

Custom Forms in WSS

January 30th, 2009 No comments

This isn’t going to be an essay or guide on how to do this, it’s just I’ve been doing this and had the following problem.

I have custom forms as the default ones don’t cut it, they don’t cut it cos of hierarchical dependencies in dropdown lists.  Now I don’t have the time to do lots of ajax or try to fight to get some ajax framework approved by, whoever, to use in my product.  So I’m using good old fashioned postbacks.

But postbacks on large forms are annoying and you need to return to the same scroll position.

Since .Net 2.0 there has been built in the MaintainScrollPositionOnPostBack directive for the @Page, something that’s as new to me as .net 2.0 (I was doing SAP for a bit for fun and a break remember ?) .

You can use this in your custom forms to.

Now I don’t know how much custom forms stuff you may have done, but I want CodeBehind in mine and struggled to get any code-behind, so I have custom forms that host another user control that I do have code-behind in.

In that Code I use the following

this.Page.Master.Page.MaintainScrollPositionOnPostBack = true;

 

Now if you have a custom master page then you can use that @Page directive instead, if your using the default on then you can use this instead.

Works a treat.

Technorati Tags: ,
Categories: Sharepoint Tags:

SPQuery DateTime query and the Time ignored

December 11th, 2008 2 comments

The U2U CAML Editor is great but it does mean you don’t take the time to learn CAML properly, eh-hum!

My queries were going very wrong and I couldn’t figure out why, so I pasted them into the CAML query tool and tested it and noticed it didn’t matter what time I set in my query it was ignored.  The CAML editor doesn’t have an option to include time values, so I could not tell what was needed to make it work.

I found this blog post http://ucsharp.wordpress.com/2007/10/11/9/.

It basically tells you that you need to tell the Query to use the timevalues and not to ignore them, this particular part of the query needs that little bit extra

<Value Type=”DateTime” IncludeTimeValue=’TRUE’>2008-12-11T16:07:00</Value>

Go test it in the CAML creator tool and see for yourself!

Thanks ucsharp.

It would seem that CAML girl looks for posts on her great tool, (I would not presume that she reads my blog!), did I miss something ? if not can you tweak a new version to have an includetimevalue checkbox (it shows people its possible)

P.S. Whilst you at it can you add

a Recently opened sites bit too

Remember user creds (securley stored in isolated storage perhaps)

I should shut up really as you can’t complain about something so handy that’s so free.

Technorati Tags: ,,
Categories: development, Sharepoint Tags:

WSS3, Workflow Hint

December 10th, 2008 No comments

When exploring workflow you might want to create a bit of code and have it execute and fire of the debugger to investigate all the properties your expecting are there.

Hint.  In your Execute Code block where you write the code to check stuff out, its worthwhile placing this BEFORE any timeout events you have in your workflow, here I am sitting waiting for the next 60 minutes before my event fires.

In fact I’m finding that a call to Debugger.Break()  doesn’t start the debugger after a timer has started, how queer normally this works on everything.

Needless to say I’m making a quick change to my workflow order for now.

 

Technorati Tags: ,,,
Categories: development, Sharepoint Tags:

Using a ListViewWebPart for Search Results

December 5th, 2008 4 comments

I have had to try and create a Search page that displays its result set in the style of a ListViewWebPart.  This has proven quite tricky.

After a lot of Searching I found various articles on using SPQuery and then the List.RenderAsHtml(Query) to achieve this.  However I found a rather large problem with this method, whilst it queries what I want it to the resulting HTML looks nice but does not do any kind of paging also whilst the sort and filter  drop downs appear at the top of the columns, they don’t actually do any sorting or filtering.

Now that was completely unacceptable.

Read more…

WSS 3 / MOSS Creating Views in CAML (List Definition)

November 6th, 2008 No comments

I have been creating custom Lists in CAML for deployment by features.  As you do.  I found out a few things that might be of help when you are creating them yourselves.

I am  Assuming that you now how to create a list template and know what goes in a schema.xml to a point.

Concentrating solely on views here I found out this.

If you have a List View WebPArt you need one of these types of views, if you don’t LVWP don’t work.

<View BaseViewID="0" Type="HTML">….</View>

Careful of BaseViewIDs being the same.

<View DefaultView="TRUE" SetupPath="pages\viewpage.aspx" Type="HTML" DisplayName="Summary" Url="Summary.aspx" Level="1" BaseViewID="1" ContentTypeID="0x"
            ImageUrl="/_layouts/images/generic.png" WebPartZoneID="Main">

<View SetupPath="pages\viewpage.aspx" Type="HTML" DisplayName="Summary"  Url="Summary.aspx" Level="1" BaseViewID="1" ContentTypeID="0x"
            ImageUrl="/_layouts/images/generic.png" WebPartZoneID="Main">

Notice that the BaseViewID’s, that wonderful field that’s barely documented, if they are both the same number then you might get problems.  I can’t explain why, but In my views I created the second view had a different Query but was ignored when created and it copied the first views query.  When I changed the BaseViewID=2 on the second view everything worked.

Is that the right thing to do ? I can’t say I’m only commenting on what I have observed.

Don’t do this

<View DefaultView="TRUE" SetupPath="pages\viewpage.aspx" Type="HTML" DisplayName="Summary" Url="Summary.aspx" Level="1" BaseViewID="1" ContentTypeID="0x"
            ImageUrl="/_layouts/images/generic.png" WebPartZoneID="Main">

<View DefaultView="TRUE" SetupPath="pages\viewpage.aspx" Type="HTML" DisplayName="Summary"  Url="Summary.aspx" Level="1" BaseViewID="1" ContentTypeID="0x"
            ImageUrl="/_layouts/images/generic.png" WebPartZoneID="Main">

If you forget when you cut and paste if you have two default views in the "Lists" page it shows up twice, its not really there twice but looks like it is.  You may not notice till too late with this one.

 

Categories: development, Sharepoint Tags:

Handy WSS / MOSS Debugging hint

November 6th, 2008 No comments

I’ve just had a chat with a colleague who was struggling to make one of our installers work.  Which reminded me of the WSS course with Todd Bleeker I was on regarding debugging and quickly trying to debug or attach to stsadm and Studio just isn’t playing.

Read more…

Categories: development, Sharepoint Tags: