I was having some troubles adding class resources to my SharePoint feature, while using WSPBuilder. I searched quite some, and here’s what I did to make it work.
First you need to start with a good project. You can build one pretty fast if you create a new WSPBuilder project and add a “WebPart with feature” to the project. Now the WSPBuilder templates should have created a project with the 12-hive folder inside your project where your webpart feature should be specified.
If you want to add a nice .jpg image to your feature, there are two ways. Embedding it in a .resx file (that’s another blogpost) or copying it to the filesystem of the SharePoint server. Of course not manually, but from inside your feature. Here’s how.
- Add a new folder and name it “80”
- Add a new folder and give it the name of your project
- Add the .jpg to this folder, or create subfolders if you’d like.
- Add the following code to your webpart to retrieve the image.
Imagine that your project is called “WebPartResources” then you’d have the structure in your project as shown in the image on the right. Right-click the project, build the WSP and you should have the roughly the following manifest.xml inside your .wsp file.
<?xml version="1.0" encoding="utf-8"?>
<!-- Solution created by WSPBuilder. 7/23/2009 10:46:15 PM -->
<Solution xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SolutionId="c8d22333-f09b-4819-b026-a6cb7d64b41a" ResetWebServer="True" xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="WebPartResources.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="WebPartResources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6763c0814d065309" Namespace="WebPartResources" TypeName="*" Safe="True" />
</SafeControls>
<ClassResources>
<ClassResource Location="dennis.jpg" FileName="dennis.jpg" />
</ClassResources>
</Assembly>
</Assemblies>
<ApplicationResourceFiles>
<ApplicationResourceFile Location="WebPartResources\dennis.jpg" />
</ApplicationResourceFiles>
<FeatureManifests>
<FeatureManifest Location="WebPartWithResources\feature.xml" />
</FeatureManifests>
</Solution>
After deploying it, you should be able with the following code to retrieve the image from this folder, although version and publickeytoken could possible change! :-)
C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\WebPartResources\1.0.0.0__6763c0814d065309
SPWeb currentWeb = SPControl.GetContextWeb(Context);
Type currentType = this.GetType();
string classResourcePath = SPWebPartManager.GetClassResourcePath(currentWeb, currentType);
Image image = new Image();
image.ImageUrl = classResourcePath + "/dennis.jpg";
How do you go about logging with Enterprise Library with the following line
Logger.Write("Hello world");
I came up with this post because I explain Enterprise Library logging to a lot of people, in a very short time. You can probably talk about logging and Enterprise Library for a long, long time. But I just want to introduce the very basics of logging. When a new developer starts working at a customer or students in my class want to know, this is the shortest possible story I tell them. That’s why I decided to write this down, as it’s still information people tend to forget easily.
I’m talking about Enterprise Library 4.1 and this is what I’ll explain:
- Adding the necessary resources (assemblies, dll files)
- Adding and understanding minimal configuration.
- Logging information with and without a specific category.
Again, I could talk about priorities and more, but this is just the basics. For more information I’d redirect you to the Enterprise Library manual on logging.
Adding necessary resources
When you’ve installed Enterprise Library 4.1 correctly, you should have the assemblies in your “Add Reference…” dialog under the .NET tab. If not, you can always add them from the folder C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008\Bin or from C:\Program Files (x86)\Microsoft Enterprise Library 4.1 - October 2008\Bin if you’re running on a 64bit machine.
Sidenote : It’s always best to copy the necessary assemblies to a project specific \lib\ folder so that everyone can use your logging solution without installing Enterprise Library. This also goes for the build server, which should obtain the assemblies from source control.

In the above image you can see the “Enterprise Logging Application Block” we should add. In Visual Studio this is the only reference you need to add. After you’ve compiled your project however, you’ll notice additional assemblies being added to the /bin/ folder. It’s out of the scope of this article, what these assemblies do. But the following assemblies are the minimum you need to use Enterprise Library logging. If you have /lib/ folder in source control, put these assemblies in, for the build server to correctly build your projects.
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.Unity.dll
Adding minimal configuration
If you haven’t, first add a web.config or app.config to your application. If installed correctly, right-click your configuration file and select “Edit Enterprise Library Configuration” as shown on the right in image 2.
The Enterprise Library configuration tool will be opened. If not, run the tool from the start menu or locate it in the above mentioned folder. After opening it, you should see the empty configuration, as shown in image 3. There’s already a connectionstring in the Data Access block, which is ‘inherited’ from machine.config.
In image 3 you can see an arrow where you should right-click and select “New” and “Logging Application Block”. When the configuration is added, these are the folders that are added
- Filters
I won’t discuss these, but they’re not too difficult to understand either.
- Category sources
Everything you log in your application, falls under a category. When you don’t specify a category while logging, the default category is used. You can see the default category added right now is called “General”.
- Special sources
When Enterprise Library tries to log something but it doesn’t work (for example you try to log to the database, but it can’t find the database) or it can’t find a category you specified, this is the place to configure what should happen then.
- Trace Listeners
If you want to log to the database, a file, eventlog or anything else, you need trace listeners. By default trace listeners are added for logging to database, file, email, eventlog, msmq, wmi and more…
- Formatters
You need formatters to… well, format your logging messages.
We’ll start with these.
Formatters
Open up the “Formatters” folder and select “Text Formatter”. In the properties pane (press F4 if it’s not there or select from the menu “View” and “Properties Window”. In the properties pane (or window) there’s a property called “Tempalte”. Select its value and press the button on the site as shown on the right.
A new dialog window should open with the current message template. As you can see there’s a lot of data there. The minimum message you can use should probably be something like below. When logging to, for example, a database or you’re tracing a lot of messages for some reason, this is probably easier to digest. You can use a cool tool like baretail to read the messages while they’re being written to the logfile on the server. When you’re logging exceptions or other information, you probably want much more detail. At the bottom of the dialog or the possible tokens you can insert. For now, leave it like it is.

However, do rename the formatter from “Text Formatter” to “My Formatter”. Now right-click any node in the configuration editor and select “Validate”. You’ll see everything validates, even though you just changed the name of the formatter. That’s how cool Enterprise Library is. ;-)
Trace Listeners
We’ll add a new trace listener as the “Formatted EventLog TraceListener” can give problems on a server because the account that’s trying to log messages isn’t authorized to write into the eventlog. Right-click the “Trace Listeners” folder and select “New” and “Rolling Flat File Trace Listener”. In the properties pane, rename it to “Rolling Flat File”. Change the filename so that it will log to a specific directory. I normally use something like “C:\Logging\ProjectName"\”. You can already specify a filter here, but we’ll leave it at “All”.
For the formatter property you’ll have to select “My Formatter”, which is the text formatter you just renamed. Also notify the other properties available. You can specify to use a time interval to create a new logfile, or a size interval. Set it to a small size, something like 1Kb so you can easily test what will happen.
Categories
Let’s add a new category and set that category as default one. If you do so, it’s probably best to remove the “General” category, as most people will think that will be the default. Create a new category called “DefaultCategory”. Select the “Logging Application Block” folder and in the properties pane select your new category to be the default one.
Right-click your new “DefaultCategory” category and select “New” and “Trace Listener Reference”. In the properties pane, change the “ReferencedTraceListener” to be your “Rolling Flat File” trace listener.
Logging information
You’re now done with the configuration. Save it and go to your code. Enter the following line somewhere in your code:
Logger.Write("Hello world");
Now go check your configured folder for the file. If it’s not that, check the eventlog anyway, as Enterprise Library might have failed and maybe has written the info there. This worked for me, as I ran into this read or write protected memory error when creating this article.
So finally they released some information on Azure pricing, or the Azure Business Model as it’s called…
First, it’ll be commercially available from PDC09 in LA this year.
| Windows Azure | SQL Azure | .NET Services |
| - Compute @ $0.12 / hour | - Web Edition – 1GB @ $9.99 | Messages @ $0.15/100K message operations , including Service Bus messages and Access Control tokens |
| - Storage @ $0.15 / GB | - Business – 10GB @ $99.99 |
| - Transactions @ $0.01 / 10K | |
Bandwith on all three will be charged at $0.10 in and $0.15 out per GB.
Customers have said that consumption based pricing as stated above might give unpredictable results. I can already imagine us opening up the slider and spend tons of computing hours, storage, etc. At PDC09 other options should be presented.
With going prices, if I would host BloggingAbout.NET on Azure, that would probably mean around $ 350,00 per month. With one VM we’d use 24 computing hours a day; our database hasn’t reached the 10GB yet, but is way over the 1GB limit of the web edition. Although I can guess other companies find $ 350 a month pretty cheap, considering they don’t need infrastructure people running around, I think I’ll stick with my own server! :-)
Just subscribed to the next Devnology meeting. This one will be an expert meeting. Normally Devnology is all about communication and sharing experiences and knowledge, but this evening Rob Vens will be speaking about Re-inventing programming. At the end there’s room for discussion though and it promises to be very interesting.
The event will be hosted at Class-A in Woerden. More information about the event can be found at the Devnology site, where you can also subscribe to the event. Seats are limited so be quick if you want to join!
The Windows Azure and SQL Data Services team have been busy. Workflow was removed from .NET Services until they can support Workflow 4 and Access Control and the Service Bus got minor updates. Read more about it here.
The SQL Data Services team has unfortunately not released anything yet, but they did gave us an update on their weblog about what they will support in version 1. From what I can quickly see is that they’ll support most functions to be able to create tables, modify data and retrieve it using the standard functions CREATE TABLE, SELECT, JOINS, Transactions, etc… Things that’ll be removed are at least everything that has anything to do with the physical machine, because everything will be hosted and maintained by Microsoft.
Read more on SQL Data Services supported features here on the SDS Team Blog.
I’ve owned a Windows Mobile for some time, currently the HTC Tytn which sure is up for replacement. But I’m really waiting for the HTC Touch Pro 2 or the HTC Hero or something. With internet on it, it’s great to have the ability to check your email, search the internet when you’re waiting or be able to find customer addresses or something. And of course the ability to tweet about what you’re doing.
For that I’ve been using Twikini for some time, and I love its features. It’s really fast, as it’s written in Native C++ for maximum performance. The menu is also laid out very well and you have the ability to create a tweet and add a twitpic with your camera while you’re at it. This ability makes it wonderful to tweet about special events with family or friends and when you see something exciting happening on the road.
Trinket Software, creator of Twikini also has some other great applications. When you buy Twikini for only $ 4.95 you’ll get an additional application for free. Or, if you blog about Twikini like I just did, you get it for free! :)
More info and downloads right here : http://www.trinketsoftware.com/Twikini