C#, Dataloading, Excel, Xml »

[25 Apr 2008 | 0 Comments]

Have you ever been given a spreadsheet to import into some system or other?

Have you then tried creating a simple dataloading program to read the data, run some dataloading rules against it before loading it into the correct fields on the target system.

Have you found this has caused problems in code because:

A) Everything is a string
B) It is hard to access the correct spreadsheet columns in code be because of a lot of column index numbers being used.
C) The Excel runtime must be installed on the computer running the data loading tool.

If you have shared this pain and have not found a better solution then please read on.
[more]

The process I now use when faced with this problem is to:

1) Define a simple xml schema per excel worksheet I need to use.
2) Map the schema elements onto the excel worksheet columns
3) Save the worksheet as ‘Xml Data’ (NOT XmlSpreadsheet)
4) Generate a .Net class using Microsoft’s Xsd tool and the same schema used on the worksheet.
5) Deserialize the ‘Xml Data’ version of the worksheet into the strongly type object created in .Net
6) Now you are in the world of .Net code and visual studio to manipulate the data in a strongly typed and intuitive way.

The attached zip file has an example of this process using data from the Northwind database.

There are two folders.

‘Step 1’ contains the source spreadsheet, schema file, example of the xml,  xsd tool, batch file to run the xsd tool, and a sample of the generated class

‘Step 2’ contains a Visual Studio 2005 solution and source code that includes the Xsd generated class, a Loader class that Deserializethe Xml file into an instance of the generated class, the Winform binds the loaded data to a DataGridView. I also included an additional partial class file to demonstrate how to extend the functionality of the generated code.

StrongTypeSpreadsheet.zip (194.80 kb)

Javascript, MS CRM4 »

[24 Apr 2008 | 53 Comments]

I've been working on a MS CRM 4 project and found that the custom entities that we added displayed an 'Add Existing xxxxx to this record' button when it was not required and created a lot of confusion among the users.

Microsoft have said they will make this optional 'In the next release' but that is not soon enough for me!
[more]

After working through various ideas on how to solve this with Ian Crowther and Steve Vallance we came up with the following fix. Thanks also to 'Dynamic Methods' for this post about hiding buttons: http://dmcrm.blogspot.com/2008/01/hiding-buttons-in-mscrm-40.html

This javascript should be added to the onLoad event for the form of the entity where you want to hide buttons for the associated views of other entities. You then need to call the function HideAssociatedViewButton for each associated entity - passing in the name of the dataArea div tag and the title of the button you need to remove. (this can be found by using the IE Developer toolbar):

The original code snippet (version 1) can be found here:

http://blog.davehawes.com/page/Remove-Add-Existing-xxxxx-to-this-record-button-version-1.aspx

This version (version 2) has been updated thanks to the contribution from David Berry. His code splits out the hiding of buttons when an iFrame is loaded into a separate function. It also allows multiple buttons to be hidden which is very useful as well as allowing the function to be used to hide buttons in other iFrames as well. Many thanks David.

Technorati Tags: ,