I recently deployed a custom user control using SmartPart on SharePoint 2007, and although everything else seemed to work fine, I came across the following error when trying to edit the properties (in my case, the chrome type and width):
Cannot save the property settings for this Web Part. Exception occurred. (Exception from HRESULT: 0×80020009 (DISP_E_EXCEPTION))
I managed to resolve this, thanks to an MSDN forum post, by changing one of my lines of code:
using (SPSite oSiteCollection = SPContext.Current.Site)
to the slightly more long-winded:
using (SPSite oSiteCollection = new SPSite(SPContext.Current.Site.ID))
I’m not sure why using SPContext.Current.Site directly (versus creating a new SPSite object) causes this behaviour, but at least it’s a simple fix.
I’m developing a simple ASP.NET page to consume an RSS feed, format and output the content. My default proxy requires authentication, so unless I supply proxy credentials or bypass the proxy altogether, I get a “407 Proxy Authentication Required” error.
Fortunately I can access the RSS feed URL directly without going through the proxy, so the solution is simple – I just need to instruct my application to ignore the default proxy settings by adding the following lines in my web.config file, within the <configuration> element:
Recently I was mystified by an issue with one of my Web applications in which the IDENT_CURRENT() function was returning null. I was under the impression that this function (which returns the last identity value generated for a specific table or view) would always return a value. In fact, as pointed out in this post, SQL Server 2005 (and presumably also later versions) requires the database user to have ALTER, CONTROL, DELETE, INSERT, REFERENCES, SELECT, TAKE OWNERSHOP, UPDATE or VIEW DEFINITION permissions on the underlying table, otherwise IDENT_CURRENT() will return null.
I can’t recall exactly how the permissions were set up in my case, but I know that the database user had SELECT permission on the entire database, and therefore was able to SELECT from the table in question – let’s call it ‘articles’. However, IDENT_CURRENT(articles) only started returning values other than null when I explicitly granted SELECT permission to the user for the specific ‘articles’ table.
This one had me flummoxed until I found the solution on the Microsoft help and support site.
Basically you need to click the “Executable” text box to initialise the path after you’ve browsed to the file.
It’s not obvious, but easy to remember once you know the workaround!
you need to use this, which will insert the correct full ID for the element and thus work correctly:
It gets a bit more complicated when using nested controls, which is explained in this post by Eric Shupps.
I’m working on a Visual Studio 2005 ASP.NET project which makes use of FreeTextBox to provide rich text editing capability. My code sets up the toolbar programmatically but, despite following the installation instructions to the letter (including setting up the FTB TagPrefix), my code was failing to compile with The type or namespace name ‘Toolbar’ could not be found on the following line of code:
Toolbar ftbTools = new Toolbar();
I initially fixed this by adding the FreeTextBoxControls prefix:
FreeTextBoxControls.Toolbar ftbTools =
But then my code fell over with a similar error on the very next line:
Not wanting to have to add the FreeTextBoxControls prefix to this and my other 18 Add statements, I instead added the following using statement to my code file:
Here’s a quick function I wrote to check whether a user is a member of a particular SharePoint group:
private bool IsMemberOf(string groupName)
SPUser user = SPContext.Current.Web.CurrentUser;
if (user.Groups[groupName] != null)
The try-catch is required as – somewhat counter-intuitively – SharePoint seems to throw a “Group not found” error if the user is not a member of the group.
I’ve spent some time today trying to figure out how to set the title of a SharePoint page from my own code. As blogger Michael Becker rightly points out, you can’t simply set Page.Title.
The correct solution, as provided by Michael, is illustrated in this example C# code:
// Get a reference to the appropriate Content Placeholder
ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)
// Clear out anything that SharePoint might have put in it already
// Put your content in
LiteralControl literalControl = new LiteralControl();
literalControl.Text = "Your text goes here";
Happily this even works when you “cheat” by hosting an ASP.NET user control within a SmartPart, as opposed to creating a bona fide Web Part.
Today I’ve been playing with Return of SmartPart 1.3, a shim which allows you to create SharePoint 2007 web parts using Web User Controls (ASCX files) created by Visual Studio/Visual Web Developer.
This is probably the least painful way for C#/VB.NET developers to delve into web part building without having to worry too much about the intricacies of the SharePoint platform.
Complete with setup wizard, comprehensive user guide and sample user controls, it’s a snap to get running, although you will need access to your SharePoint server both to install the SmartPart and any custom user controls. It also optionally supports AJAX controls, after installing Microsoft’s ASP.NET AJAX extensions.
There’s no need to use strong naming or even compile your controls – just drop the .ascx (and .ascx.cs/.vb, if necessary) files into your usercontrols directory and you’re good to go.