Microsoft Chart Controls for .NET – Error executing child request for ChartImg.axd

3 11 2009

I ran into this error today when attempting to show a web part on a SharePoint site that utilises the .NET 3.5 Chart Controls from MS (See link at the bottom of the post).

When the page opened it bombed out with the above error, some research found the following question on stackoverflow –

http://stackoverflow.com/questions/302820/net-3-5-chart-controls-exception-error-executing-child-request-for-chartimg-axd

To fix this error you need to add the following entry into the <HttpHandlers> section of the web.config file:

<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

When I refreshed the page, I received another error – this time it was:

Invalid temp directory in chart handler configuration

If you too get this error then you need to make sure you have the following line in the <appSettings> section of the web.config:

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />

Also make sure that the above directory ‘TempImageFiles’ exists on the C: drive or you can change this to any other directory that you like.

Hope this helps! :-)

Download link for MS Chart Controls:

http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C&displaylang=en





SPListitem.File.Versions – System.Argument.Exception

28 10 2009

I was writing some code yesterday to loop through the list items in a SharePoint list and then loop through each version of the SPListItem’s underlying file.

Here is the code I was using -

using (SPSite site = new SPSite("http://theserver/"))
           {
               using (SPWeb web = site.OpenWeb())
               {
                   SPList list = web.Lists["The List"];
                   SPView view = list.Views[new Guid("D9E7BDDC-4C77-4386-BA0E-A786D58EE199")];

                   SPListItemCollection itemCol = list.GetItems(view);

                   foreach (SPListItem item in itemCol)
                   {
                       foreach (SPFileVersion version in item.File.Versions)
                       {
                           string url = version.Url;
                       }

                   }
               }
           }

When the code hit the ‘item.File.Versions’ collection it threw a System.Argument.Exception. This really stumped me and I couldn’t figure out at all while the collection was throwing this exception.

After a lot of researching I found this blog post –

http://www.mtelligent.com/journal/2007/10/17/the-insanity-of-getting-versions-of-a-multilinetext-box-set-.html

In this post, David talks about getting the same exception when he is trying to access the list item’s file versions. If you scroll down and look at the comments you you will see that this only seems to be a problem if you are getting the SPListItem as the result of an SPQuery (in my case the spquery is actually an SPView).

This is most likely because getting the item using an SPQuery returns the list item with a minimum amount of data, therefore the versions are not accessible.

The solution here is to create another instance of the SPListItem by using the GetItemById() method which will return all the properties for the list item. This way the SPListItem.File.Versions collection will be accessible and we can iterate through it.

See the correct code –

using (SPSite site = new SPSite("http://theserver/"))
           {
               using (SPWeb web = site.OpenWeb())
               {
                   SPList list = web.Lists["The List"];
                   SPView view = list.Views[new Guid("D9E7BDDC-4C77-4386-BA0E-A786D58EE199")];

                   SPListItemCollection itemCol = list.GetItems(view);

                   foreach (SPListItem item in itemCol)
                   {

//Get a reference to the item again by the ID

SPListItem theItem = list.GetItemById(item.ID);

//The versions collection should now be populated (if versions are available) and no exception should be thrown

                       foreach (SPFileVersion version in theItem.File.Versions)
                       {
                           string url = version.Url;
                       }

                   }
               }
           }

Hope this helps someone! :-)





Copying files to the 12 Hive with VSEWSS Extensions 1.3

26 10 2009

This had me stumped for a while earlier, I had created a Web Part project and wanted to include an image to be deployed to the TEMPLATE\IMAGES directory of the 12 hive.

Originally I added a module to the project but this would then copy the image to a folder in the actual site itself which I didn’t want.

The solution is to use a ‘Template’ –

Right click on the project in Visual Studio and select Add > New Item

Add new template to the project

Select a ‘Template’ and give it a name, this will add a folder in your solution called ‘Templates’ with a text file inside that has the name you gave above.

You can then add the 12 hive TEMPLATES folder structure under here and any files will be copied to the 12 hive when the wsp solution package is installed.

Templates folder within solution

Hope this helps!





SPBuiltInFieldId – Very useful

22 10 2009

If you ever need to get the GUID of a built in SharePoint field such as ‘IssueStatus’ (from the standard ‘Issue Tracking’ list) for example then you can use the SPBuiltInFieldId class.

This class contains a number of GUID objects for each type of built in SharePoint field.

To use it simply use the following code:

Guid issueStatus = SPBuiltInFieldId.IssueStatus;

I found this very useful, hope it helps some of you!





VseWSS 1.3 CTP March 09 – Still Buggy

15 10 2009
I’ve been developing a web part today and thought I would try the VseWSS extensions to see if they would get the job done quicker, I normally just create the Visual Studio solution myself and use WSPBuilder (http://www.codeplex.com/wspbuilder) to deploy it.

After I had built my web part I clicked to debug and was presented with the following error:

clip_image002_2

To get past this error I used the following two blog posts:

http://blogs.msdn.com/steve_fox/archive/2009/03/18/vsewss-1-3-post-install-configuration.aspx

http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/02/05/vsewss-1-3-ctp-feedback-and-feature-requests.aspx

It seems that the error is because the account running the application pool for VseWSS web application in IIS does not have the correct permissions. I was on a domain controller so simply gave the account domain admin permissions. This however did not fix the error and I ended up giving the account full control to the folder itself!

When I tried to deploy again I did not get the above error but now a different one (See screenshot below)! I cannot find any more details on this error and the folders specified in the error message do not even exist.  I think im going to go back to using WSPBuilder from now on as it seems the VseWSS extensions are still quite buggy.

Untitled

If anyone has any more details on the above error and how to fix it then please let me know :-)





Get URL Value of SharePoint Hyperlink Field

12 10 2009

I needed to get the value of a SharePoint hyperlink field in a custom list the other day so I simply tried to access the value of the field directly in the object model:

SPListItem item = list.GetItemById(1);

string URL = item[“URL”].ToString();

The only problem with this is whilst it gets the value, you end up with two URL’s separated by a comma. This is because one is the actual display text for the field and the other is the value (the actual URL itself).

In order to get just the URL value, you need to use the following object model code:

SPFieldUrlValue value = new SPFieldUrlValue(item[“URL”].ToString());

string URL = value.Url;

You can also use value.Description to get the actual display text for the field.

Simples! Hope this helps :-)





Obtaining workflow status in code

14 09 2009

I recently wrote a console application which looped through the workflows running on my SharePoint site and showed the status of each one. When I refer to status I mean the same status that is displayed under the workflow column e.g. In Progress, Error occurred etc

To get the workflow status in code you need to use the enumeration ‘SPWorkflowStatus’, which will return one of the following numeric values:

public enum SPWorkflowStatus
{
NotStarted = 0,
FailedOnStart = 1,
InProgress = 2,
ErrorOccurred = 3,
StoppedByUser = 4,
Completed = 5,
Max = 15,
}

Hope this helps!





Enabling .NET 3.5/AJAX in MOSS 2007 Sites

6 08 2009

I have been searching for a decent blog post/tutorial on how to enable .NET 3.5 in a MOSS site for a while now.

I first came across the following blog post that describes how to enable ASP AJAX 1.0 in MOSS –

http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3

So I modified the web.config as per the above guide and it works great!

…However the .NET framework 3.5 contains a newer version of AJAX which I’m sure would be the preferred choice to use.

I finally came across this post by Tobias Zimmergren where he walks through the changes that need to made to the web.config –

http://www.zimmergren.net/archive/2008/09/22/how-to-get-up-and-running-with-net-3-5-in-your-sharepoint-environment.aspx

Thanks Toby! As I understand there are other less ‘manual’ ways of doing this that do not involve directly editing the web.config but these can have their problems and I think that the manual way feels more thorough.

Hope this helps someone!





WSS & MOSS – workflowProperties.Item.Update causes new versions

29 06 2009

I haven’t really worked with workflow in a document library with versioning turned on yet…until now.

What we found is that each time some metadata of the document was changed using workflowProperties.Item.Update, a new version of the of the file was created!

You could argue that  this is OK and for the majority of implementations this would probably be fine however we needed to find a way around it:

If you do not want to re-version the document when a workflow changes the metadata then you can use the workflowProperties.Item.SystemUpdate method, see the details here –

http://msdn.microsoft.com/en-us/library/ms461526.aspx

The SystemUpdate method writes the data directly to the database and also accepts a boolean flag defining whether or not to increment the version number, perfect!

Hope this helps! :-)





Logging to the SharePoint ULS logs programmatically

18 06 2009

When writing SharePoint applications error messages should be handled appropriately, as well as displaying a message to the user it may be useful to log this message to the SharePoint 12 hive error logs. The SharePoint error logs sit in the following location of the server – 12 Hive\LOGS.

To write a message to the log directly from custom code you can use the Microsoft.Office.Server.Diagnostics.PortalLog class, simply reference the Microsoft.Office.Server.dll and use the following method:

PortalLog.LogString(yourerrormessage)

The LogString method accepts a string so just pass in your exception message and your good to go. Additionally the ‘DebugWriteString()’ method works the same way as the above but allows you to specify the level of the item that you are logging (Critical, Error, Information or Verbose).

Hope this helps someone! :-)