Monday, 4 March 2013
Guess who's back?
Posted by
Unknown
at
09:50
Tuesday, 24 November 2009
Debugging SmartPart User Controls
Ok, so you are faced with this situation
1. You are using SmartPart because its easier for your .NET developers to write UserControls, rather than WebParts (thank god for SharePoint 2010 where developing webparts will be easier at last).
2. Using SharePoint functions such as using SPContext and local debugging (i.e. using a normal web application for testing rather than SharePoint) present a headache, since the context is not available when you are debugging locally.
3. You need the best of both worlds, i.e. easy and quick debugging, but using SmartPart and user controls.
1. Create post build events which copy your User Control dll to the SharePoint folder, and your user controls to the UserControls folder
e.g. copy c:\develpment\xxx.dll c:\inetpub\wwwroot\80\wss\...

2. On the Web Application project properties, rather than using the Visual Studio web server for debugging, use the IIS webserver and specify the web application where your user controls are getting deployed.

3. Press F5 and voila, your dlls, and User Controls files are copied to SharePoint, and SharePoint is loaded and attached to the debugger.
This will now allow you to step into your User Control's code whilst having all SharePoint functions still available! :)
Posted by
Unknown
at
17:05
Monday, 5 October 2009
Reading Settings from the Web.Config file from an Event Handler
The SharePoint web.config is in my opinion the best place to put in any configuration settings. To read the config settings from an Event Handler isn't so straight forward but the following code does it nicely:
The SPItemEventProperties comes from the EventHandler.
<add key="Username" value="svc-sharepoint"/>
public static string ReadKeyValueSetting(SPItemEventProperties properties, string keyName)
{
EventLog evita = new EventLog();
evita.Source = ("ReadFromConfig");
string webApplicationName = "";
using (SPSite siteCollection = new SPSite(properties.SiteId))
{
if (string.IsNullOrEmpty(siteCollection.WebApplication.Name))
throw new ApplicationException("Web application name is empty!");
else webApplicationName = siteCollection.WebApplication.Name;
}
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplicationName);
if (config == null)
throw new ApplicationException("Web Configuration is null");
AppSettingsSection appSettings = config.AppSettings;
if (appSettings == null)
throw new ApplicationException("Web.config appSettings section cannot be found!");
if (appSettings.Settings[keyName] == null string.IsNullOrEmpty(appSettings.Settings[keyName].Value))
{
evita.WriteEntry("KeyName doesn't exist!", EventLogEntryType.Warning);
throw new ApplicationException("Key value cannot be read from appSettings. Make sure this key and its value exist!");
}
return appSettings.Settings[keyName].Value;
}
Posted by
Unknown
at
15:48