Blog of an overweight SharePoint addict

Tue 24 Nov 09

Should I change the name?

To once a month updates?

I haven’t stopped since I got back from SPC and have been dashing around between clients working on SharePoint 2007 issues. Doesn’t anyone understand I want to play with SharePoint 2010 now? Or more to the point, I need to upskill in some areas very quickly to get the most of SP2010 and all the goodness it brings.

Looking at whats coming in SP2010, I honestly think the IT Pro’s have got it easy.. You guys just have to learn one new application, Us Devs have to learn at least 2, SP2010 and Visual Studio 2010!

Then on top of that, we have an updated object model to contend with, along with a brand new object model in the form of the SharePoint Client OM!

Add to this the requirements to use XSLT for almost every list view in SP2010, SPLinq (Call it SPlinq, MS hate that!!), Silverlight and a lot more Javascript than before, all adds up to a lot of skill-up time!

So here’s to spending many evenings and train journeys in front of Visual Studio, playing with Silverlight 101 and all the new Sharepoint tools that now come out of the box with VS!

I’m booked up in December as solidly as November was, so i wouldn’t expect too many posts on here just yet, although I am planning to extend the piece I wrote on KPI’s to give more ideas and hopefully present on this at a SUG do in the early new year.

Regards

Paul.

Wed 4 Mar 09

SharePoint Dispose Checker Tool

Filed under: General, Programming, SharePoint, Visual Studio 2005 — Reginald @ 11:51 am

The Microsoft SharePoint team have released a SharePoint disposal checker tool to the MSDN community. This command line tool scans individual asseblies, or entire directory structures and analyses the code for memory leaks through poor disposal.

I ran it against some of my assemblies and I’m happy to say only my quick command line tools written for testing exposed any poor disposal issues.. (Mainly because I don’t bother worrying about disposal when I’m just testing constructs..)

The project site can be found here with further links to the team behind the tool.

http://code.msdn.microsoft.com/SPDisposeCheck

Reg.

Tue 30 Sep 08

A question of authorisation..

Filed under: General, Programming, Security, SharePoint, Visual Studio 2005 — Reginald @ 3:27 pm

I’m writing some custom application pages that run from the _Layouts directory. They’re triggered by items on the Edit Control Block menu.. (See the previous post from the other day on this option..)

One of the things that has really come up with this is the question of authorisation, and confirming that the user does have the rights for what you’re attempting to do. For the work that I’m doing, this means checking those rights in two places.

The first place is the Edit Control Block that we’re placing the menu option into. This is defined in your elements.xml as a CustomAction. One of the useful features about custom actions, is that you have two elements available to hide them from inappropriate users.

The first is the RequireSiteAdministrator element. This does exactly what it says on the tin, If the current context user is a Site Admin, they get the menu option, if not, they don’t.

RequireSiteAdministrator = "TRUE"

The second option is based on the SPBasePermissions enumeration and is a comma separated list of ALL the permissions that a user must have on a list item before the menu option is shown.

Rights="EditListItems,ApproveItems"

Click here for more information on SPBasePermissions

BUT.. And there is always a but… if your user knows the URL and the format of the query string, they can always type that in directly, so you must include a security wrapper in your application page.

E.g.

try
{
     if (sourceItem.DoesUserHavePermissions(SPBasePermissions.ApproveItems) && sourceItem.DoesUserHavePermissions(SPBasePermissions.EditListItems))
     {
 
         //Do stuff
 
     }
     else
     {
        throw new SecurityException("You do not have the required rights for that operation.");
     }
}
catch (SecurityException ex)
{
         SPUtility.HandleAccessDenied(ex);
}

As you can see, we can place the authorisation failure into the try/catch block, and just throw a SecurityException to call the redirect functionality from the SPUtility model. This presents the user with the familiar Access Denied page.

Cheers

Reg.

Wed 24 Sep 08

Adding a ContentType Specific item to the ECB (Edit Control Block)

Filed under: Programming, SharePoint, Visual Studio 2005 — Reginald @ 4:29 pm

There’s plenty of articles on the net that tell you how to add items onto the Edit Control Block for a given list type, But I found articles on Content Types to be in short supply..

So, for the benefit of Mr google bot… (Edit Control Block Entries for Custom Content Types)

How do we do it, well it’s quite simple. Go to Site Settings, Site Content types and click on the content type you want to affect. In the URL that opens you’ll see something similar to “ctype=0×0100140835253A1B6F4E8B40A833287BB367

Grab that sortof GUID and add the following entries into your ECB declaration in the Elements.Xml file of your feature..

1
2
3
4
5
6
7
8
9
10
11
12
  <CustomAction Id="UpdateDeliveryState"
  RegistrationType="ContentType"
  RegistrationId="0x0100140835253A1B6F4E8B40A833287BB367"
  ImageUrl="/_layouts/images/customimage.jpg"
  Location="EditControlBlock"
  Sequence="242"
  Rights="EditListItems" 
  Title="Update Delivery State" >
    <UrlAction Url="~site/_layouts/UpdateDeliveryState.aspx?ItemId={ItemId}&amp;ListId={ListId}&amp;Source=http%3A%2F%2Fdemosite"/>
  </CustomAction>
 
Reg.

Wed 17 Sep 08

Integrating Search Server Express – reprised.

Filed under: Programming, Search, SharePoint, Visual Studio 2005 — Reginald @ 10:16 am

I’ll be one of the first to admit, Javascript is NOT my strong point.. or my favorite.. C# however is, so I amended the ASCX page to use C# throughout.

2 ASP controls for the Image and text box both of which have a click event “cmdRunSearch_Click”

This calls:-

protected void cmdRunSearch_Click(object sender, EventArgs e)
    {
	string strEncodedUrl
		= SPEncode.UrlEncodeAsUrl("http://demosearch/results.aspx",false);
 
 
    string targetUrl = strEncodedUrl + "?k=" + txtSearchText.Text;
 
    Response.Redirect(targetUrl);        
    }

A little bit of styling on the asp objects and the new control adapter looks the part and performs well.

The only downside to this approach is that the ascx page has to be edited manually after the feature is installed to ensure the correct URL is used for the SSE implementation.

To take this further, I’m tempted to restore the scope activities that I took out of the original MS page, however this time we need to pull the scope options from the search centre, so this may need some thought.

Reg.

Tue 16 Sep 08

Integrating Search Server Express into WSS 3.0 Team Site.

Filed under: Programming, SharePoint, Visual Studio 2005 — Reginald @ 2:54 pm

Just recently we installed Search Server Express for a client on their WSS infrastructure. It’s working quite nicely having a much more granular control than the standard WSS search functions, but my main gripe is the lack of SmallSearchServer control to replace the existing WSS one.

Most users would rather click into a text box at the top of the page, and enter their search query than click off to another search url and perform the action there. So, we need to remove the WSS search input and replace it with our own.

Now, thanks to Microsoft using Delgate controls on the master page, this is nice and simple. All we need is a feature consisting of the standard Feature.Xml and Elements.Xml and the new controltemplate, in this case BSSearchArea.ascx.

So far so good. I’ve customized the existing SearchArea.ascx taken from 12/TEMPLATES/CONTROLTEMPLATES and i’ve removed all mention of the scope. My elements file has been configured to override the existing control using:-

  <Control
		Id="SmallSearchInputBox"
		ControlSrc="~/_controltemplates/new.search/BSSearchArea.ascx"
    Sequence="10"
	/>

And my control is appearing as expected. but my problem now is the error that appears when I enter a search term and click search. I receive:- “This Page has been modified since you opened it. You must open the page again.”

Well I know that the submit button is calling a SharePoint javascript function, so I decided to pull a copy of that out of core.js and put it inline with my ascx after removing anything i don’t want.

So now I’m left with the function called by my form button onClick() event.

function bsSubmitSearchRedirect(strUrl)
{
    var frm=document.forms["frmSiteSearch"];
    if (frm==null)
    {
        if (typeof(MSOWebpartPageFormName) !="undefined")
            frm=document.forms[MSOWebPartPageFormName];
    }
    if (frm !=null)
    {
        var searchText=frm.elements["SearchString"].value;
        strUrl=strUrl+"?k=" + escapeProperly(searchText);
        frm.action=strUrl;
        frm.submit();
    } 
 
}

But I’m still having this errpr when searching.. the weirdest thing about it though, if you click the refresh page link in the error.. it works perfectly..

Watch this space..

Wed 27 Aug 08

How to brand your WebPart solutions..

Filed under: Programming, SharePoint, Visual Studio 2005 — Reginald @ 3:05 pm

So you’ve written a nice web part solution, ready to release it onto your clients environment, but wait a minute! How do they know you wrote it for them? All you’ve got is those generic icons that microsoft provide you.

This is the situation i found myself in recently, and realised that with my change in job role comes the requirement to make sure people are aware of the things that I’ve done. To this end, I decided to make sure that the company log is displayed in the Feature Activation page and in the Web Part Catalog.

At this point, I’m going to assume that you’re aware of Features and how to wrap them up in a solution package.. if you’re not, then this might not be the best post for you to start at.. in fact I’d suggest you get a copy of Inside Microsoft Windows SharePoint Services 3.0 by Ted Pattison and Daniel Larson.

Starting at the solution level, we need to place the icon that we want to use into an area accessible by the Web part. what better place than _Layouts/Images?

If you’ve followed the recommend webpart creation guidelines, you should have a directory structure in your VS2005 project that resembles TEMPLATE\FEATURES etc etc..

now under TEMPLATE add a new directory of IMAGES and then your own directory under this e.g. CUSTOMLOGOS (This is best practice to seperate your images from Microsofts in the IMAGES directory to avoid filename conflicts.)

In this directory, place your chosen .JPG file which should be approximately 44 pixels square.

The first task is to ensure that this file is included in your .WSP package. To do this, make sure the following line is in your DDF file. (NB: this is all on one line.. but my blog isn’t wide enough to display it!)

TEMPLATE\IMAGES\CUSTOMLOGOS\custom_logo_44sq.jpg IMAGES\CUSTOMLOGOS\custom_logo_44sq.jpg

And in your manifest.xml you’ll need a corresponding entry:-

<TemplateFiles>
<TemplateFile Location="IMAGES\CUSTOMLOGOS\custom_Logo_44sq.jpg"/>
</TemplateFiles>

The section above basically just copies your chosen logo into the IMAGES and makes it available using the URL \IMAGES\CUSTOMLOGOS\custom_logo_44sq.jpg

The next step is to make this icon appear on the Feature activation page. This is very simple to achieve and just a matter of adding or amending the ImageUrl property of the Feature tag in your Feature.XML

<?xml version="1.0" encoding="utf-8" ?></code>
<Feature
  Id="00000000-0000-0000-0000-000000000000"
  Title="My custom branded web part"
  Description="This feature uses custom branding."
  Hidden="FALSE"
  Scope="Site"
  ImageUrl="BlueSource/BlueSource_Logo_43sq.jpg"
  xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
    <ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>

And then finally we want to make the image appear in the Web part gallery. This requires a change to the webpart file itself. Inside the Properties markup, add a new property tag similar to the following:-

<property name="CatalogIconImageUrl" type="string">/_layouts/images/bluesource/bluesource_logo_43sq.jpg></property>

NB: Ensure that you don’t add any carriage returns or line feeds in the above statement. If you do, then there is a good chance that your image will only appear on either the pop up webpart catalog, or the advanced web part window, but not both. if that happens, check the line above in your .Webpart file.

And there you have it.. Deploy your solution and your icon will be visible on both the Feature activation screen and the Webpart gallery screen.

I hope this helps.

Reg.

Mon 7 Jul 08

Upgrading Features.

Filed under: General, Programming, SharePoint, Visual Studio 2005 — Reginald @ 5:26 pm

I’ve been quite naughty recently and I’ve been taking the easy way out when it comes to putting code upgrades in. It’s very easy to drag the DLL from the dev environment and just drop it into either the Gac or the local Bin, without any thought to what happens if someone comes along and re-uses the .WSP file in future!!

So today I actually spent some time figuring out the stsadm -o UpgradeSolution command and testing it on my live environment to perform some upgrades to live code. The result, it worked quite nicely thank you and I’ve documented this into our ongoing procedures.

So, How does it work, Well in reality, it’s no different from deploying a solution for the first time. You copy your WSP file into the holding area, in my case it’s D:\InboundProjects.

Then enter the following command (tailored to fit your deployment options of course..)

stsadm -o UpgradeSolution -name MYSOLUTION.WSP -filename D:\inboundprojects\MYSOLUTION.WSP -immediate -allowcaspolicies

Follow this with a quick stsadm -o execadmsvcjobs to force the time job to run and bingo, the code is live. And just for my own happiness, I had an explorer window open to the local webserver wpcatalog directory just to be certain it updated the deployedf files correctly, which it did.

Reginald.

Thu 29 May 08

Using the undocumented SPUtility.SendEmail method.

Filed under: General, Programming, SharePoint, Visual Studio 2005 — Reginald @ 3:31 pm

As with a lot of the sharePoint API, the SPUtility class and more importantly the sendEMail method lacks a decent amount of documentation on its use.

After a little bit of playing around with a console session, I’ve found what seems to be the best way to use this function. (For me at least.. feel free to disagree!!)

Requires:
using System.Collections.Specialized;

For the purposes of my test code, I used a console sessions and wrapped the send email process inside two using statements to populate site and web with the test sharepoint site.


StringDictionary headers = new StringDictionary();
headers.add("to","reginald@myfatblog.co.uk");
headers.add("cc","thisiscopy@myfatblog.co.uk");
headers.add("bcc","thisistheblindcopy@myfatblog.co.uk");
headers.add("from","MySharePointEmail@myfatblog.co.uk");
headers.add("subject","How to use SendEMail from SPUtility");
headers.add("content-type","text/html"); //This is the default type, so isn't neccessary.

string bodyText ="This is the body of my email, in html format.";

SPUtility.SendEmail(web, headers, bodyText);

The SendEmail method makes it very easy to pop emails out using your SharePoint sites current SMTP configuration, the only downside is that this does not allow you to use attachments. If you need to do this, then you’ll need to look down the .Net mail methods.. (I found a decent post on David Fekkes blog on how to do this using the .Net methods. I haven’t tried it yet, but it’s a good starting point. Email with attachments from SharePoint code.

Thu 8 May 08

Field Type errors in webparts.

Filed under: Programming, SharePoint, Visual Studio 2005 — Reginald @ 10:29 am

I’ve been making some changes to the Summaries webPart this week following the successful beta with the users. The key problem I hit was an unexpected error when changing one of the selected views in the web part. I received a very helpful

“One or more field types are not installed properly. Go to the list settings page to delete these fields.”

Well this is a very useful error, Resolve the problem by deleting the fields causing the issue? in this instance however, there isn’t actually a problem, The issue is caused by the CAML used to return the data for the webpart. In Dev, it was looking for “Projects_x0020_Task_x0020_Complete” and in Live it should have been “Projects_x0020_Involvement_x0020_Complete”. Simple schoolboy error and easily solved, but not helped by the error message, so one to watch out for in future.

Update: This came about because the column had been renamed long ago, therefore the program I used to extract the column name showed the internal name of Project Tasks Complete, whereas I had renamed it to Projects Involvement Complete before porting the whole lot to live!

Older Posts »

Powered by WordPress