2008 April

Getting your controls to appear in Sharepoint Designer Toolbox

The guy over at thekid.me.uk has posted a v. handy little note about how to get your a servers control into the toolbox in Sharepoint Designer.

Apart from registering your control within the SafeControls part of the web.config), the secret sauce is to add :

[ToolboxData(“<{0}:ControlName runat=server />”)]

to your class (just above the class declaration)

and

[assembly: TagPrefix(“yournamespace”, “selected prefix”)]

What then happens when you drag the control into designer is that it inserts

<prefix:ControlName runat=server /> into the page.

By admin on April 28, 2008 | c#, Development, Sharepoint | A comment?

Personalizable attribute of web part properties

Why does everything Sharepoint require a trip to Google? Oh well.

If you’re trying to make a web part property editable you need two attributes, Personalizable and WebBrowsable.

You need the WebBrowsable property in order to see the property via the web interface in Sharepoint.

You need the Personalizable propetry to be able to edit it.

However, Personalizable sounds like it’s tied to an individual user (and not all users). Like many things Sharepoint it depends.

Quick answer:

Personalizable(PersonalizationScope.Shared): Single value for all users
Personalizable(PersonalizationScope.User):
Different value for all users

I’m not sure which is default, but according to this it’s the User Scope. Read the msdn article for a more detailed breakdown.

Credit goes to Marco Bellinaso, as I found the reference to the PersonalizationScope on his blog.

By admin on April 27, 2008 | c#, Development, Sharepoint | A comment?

Relative URLs in Sharepoint Web Parts

If you’re using STSDev for web part development, it becomes very simple to deploy files into the 12Hive (which in some circumstances is preferable to using embedded resources). As a consequence, it becomes tricky to create hyperlinks to resource files because:

  • you can’t guarantee the web part is sitting in root of the site collection (which would make for simple hyperlinks ala “_layouts/styles/myPart/myCSS.css”)
  • you can’t know that your site collection is located at the root of the web server (which would make for simply hyperlinks ala “_layouts/styles/myPart/myCSS.css”

So, to create simple relative urls from code (as opposed to using the <% $SPURL:~sitecollection/_layouts/styles/myPart/myCss.css %> approach) I used something I found on Ari Bakker’s website.

Deep underneath the SPContext object is a property called ServerRelativeUrl which is attached to the Site(SPWeb) and Site collection(SPSite) objects.

These can be used by the web part to refer to resource files deployed along with it. So, something like the following should work anywhere inside a site collection:

string cssLocation = SPContext.Current.Site.ServerRelativeUrl + “_layouts/styles/myPart/myCSS.css”;

By admin on April 21, 2008 | ASP.NET, c#, Code, Development, Sharepoint | A comment?

How to fix the “SQLExpress database file auto-creation error” message

I encountered this problem while trying to develop webparts on a my development machine with Sharepoint 2007 (a win2k installation), and found a solution on this page.

Initially the problem occurred because I hadn’t rerun the aspnet_regsql.exe utility. So I did, but I already had SQL Server installed when I setup Visual Studio. As a consequence, SqlExpress wasn’t installed and I used the full-blown SQL install setup with Sharepoint. If you don’t have Sharepoint on your machine, adding the following to your application’s web.config should work just fine:

<connectionStrings>
<clear/>
<add name=”LocalSQLServer” connectionString=”Server=.;Database=aspnetdb;trusted_connection=yes”/>
</connectionStrings>

That got me most of the way, but because I used my SharePoint install, the ASP.NET databse went onto #YourServername#\OFFICESERVERS.

To resolve this you need to change the string to.

<add name=”LocalSQLServer” connectionString=”Server=#YourServerName#\OFFICESERVERS;Database=aspnetdb;trusted_connection=yes”/>

Sorted.

By admin on April 19, 2008 | c#, Sharepoint | A comment?

Broken intellisense when working with Microsoft Sharepoint

I have to say, getting up to speed with WSS/MOSS programming is rather difficult after four years of having nothing but javascript and vba.

One thing that’s is evident is that Intellisense is vital to being productive. It’s just far too slow to develop without it.

So when Intellisense died in VS2005, I got grumpy. It wasn’t totally dead, just mostly dead. It would still give me references to strings and stuff, but the entire Microsoft.Sharepoint library was Intellisense free.

I eventually found a solution on my own, although I won’t claim to understand it.

in the 12 Hive there’s a file called Microsoft.Sharepoint.xml, which seems to contain the Intellisense definitions. All you need to do is “touch” it (i.e. change the file modification date), restart Visual Studio, and Intellisense springs back to life.

The file is under the ISAPI folder. Take a backup obviously.

I did try two other things which may or may not have helped.

I cleared out all the files in:

C:\Documents and Settings\Administrator\Application Data\Microsoft\VisualStudio\8.0\ReflectedSchemas

which is apparently the Intellisense cache. I did this before playing with Microsoft.Sharepoint.xml, but only had a little joy (a few more things came back but nothing in Microsoft.Sharepoint).

I also removed the Microsoft.Sharepoint.dll and added it back in, but can’t tell if it helped or not.

By admin on April 16, 2008 | c#, Development, Sharepoint | A comment?