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.
Here's the way to do it:
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! :)
Tuesday, 24 November 2009
Debugging SmartPart User Controls
Posted by
dattard
at
17:05
Links to this post
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.
You need to put in an appSettings tag in your web.config file, and then as many key value pairs as you need:
<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
dattard
at
15:48
Links to this post
Monday, 28 September 2009
Using HTML to create visual graphics in SharePoint
ok, so you want to create some basic KPIs without installing / buying any webparts. You can do that, using a combination of Calculcated Columns and the Custom Editor Web Part.
Good Stuff, see more details here: http://pathtosharepoint.wordpress.com/2008/09/01/using-calculated-columns-to-write-html/
Posted by
dattard
at
14:29
Links to this post
