Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Contents tagged with C#

  • Programmatically reuse Dynamics CRM 4 icons

    The team that wrote the dynamics crm sdk help rocks!

    I wanted to display the same crm icons on our time tracking application for consistency, so I opened up the sdk help file, searched for 'icon', ignored all the sitemap/isv config entries since I know I want to get these icons programatically, about half way down the search results I see 'organizationui', sure enough that contains the 16x16 (gridicon), 32x32 (outlookshortcuticon) and 66x48 (largeentityicon) icons!

    To get all the entities, execute a retrieve multiple request.

    RetrieveMultipleRequest request = new RetrieveMultipleRequest
    {
        Query = new QueryExpression
        {
            EntityName = "organizationui",
            ColumnSet = new ColumnSet(new[] { "objecttypecode", "formxml", "gridicon" }),
        }
    };
     
    var response = sdk.Execute(request) as RetrieveMultipleResponse;

    Now you have all the entities and icons, here's the tricky part, all the custom entities in crm store the icons inside gridicon, outlookshortcuticon and largeentityicon attributes, the built-in entity icons are stored inside the /_imgs/ folder with the format of /_imgs/ico_16_xxxx.gif (gridicon), with xxxx being the entity type code. The entity type code is not stored inside an attribute of organizationui, however you can get it by looking at the formxml attribute objecttypecode xml attribute.

    response.BusinessEntityCollection.BusinessEntities.ToList()
        .Cast<organizationui>().ToList()
        .ForEach(a =>
        {
            try
            {
                // easy way to check if it's a custom entity
                if (!string.IsNullOrEmpty(a.gridicon))
                {
                    byte[] gif = Convert.FromBase64String(a.gridicon);
                }
                else
                {
                    // built-in entity
                    if (!string.IsNullOrEmpty(a.formxml))
                    {
                        int start = a.formxml.IndexOf("objecttypecode=\"") + 16;
                        int end = a.formxml.IndexOf("\"", start);
     
                        // found the entity type code
                        string code = a.formxml.Substring(start, end - start);
                        string url = string.Format("/_imgs/ico_16_{0}.gif", code);


    Enjoy!

  • Tax rules for Dynamics CRM 4

    Now that Tax (G.S.T) is about to change here in New Zealand it's probably a good time that you check with your dynamics crm implementor/developer if you're going to get pinged for changing 12.5% to ...

    We've created an addon for dynamics crm that automatically calculates tax. It works on any entity (even custom ones), you can specify different rates, different rates for different currencies and/or combinations of both on any entity as long as there is an amount and a tax field.

    For example, take a look at the screenshot below, we've configured the tax rules plugin to run on an invoice line item.


    Future proof your dynamics crm by contacting us and installing this plugin!

  • Web Form to Dynamics CRM 4

    We've decided to release another component we've been using internally. This little webcontrol allows you put pass data from a Web Form to Dynamics CRM 4.

    How does it work?
    Create a UserControl to layout the form.

  • CRM 4 Activity Direction Indicator (experimental)

    I've been trying to change the icons under History for each entity to show the direction of the email or phone call.

    Using Fiddler I found out that areas.aspx was responsible for rendering the grid when you click on History, then when you click on the Refresh button or create a new Activity it automatically refreshes the grid, that call is made into the AppGridWebService.asmx which returns the formatted html of the grid.

    Unfortunitely I'm not sure how I can hook into the .asmx and modify the returned html.

    Leaving AppGridWebService.asmx aside for now, areas.aspx was easy to hook into, here is the result.

    1st Phone call: an outbound call which is displaying the custom outbound phonecall image.
    2nd; an inbound call, lastly the email is an outbound email with a custom icon.

    To hook into areas.aspx create a new HttpModule then on BeginRequest

  • CRM 4 Incremental Numbering for any Entity

    UPDATE 08/01/2009
    - Project is now on CodePlex (http://www.codeplex.com/crmnumbering/)

    MYOB can only take 8 characters and accountants don't like seeing cryptic Invoice Numbers that CRM generate, so we ended up writing a custom plugin that automatically incremented each invoice. Keeping extensibility in mind we made it work with any customizable entity. Here is how we did it.



    We created a simple organization owned entity that held the type of entity you wanted to increment, the property/field you wanted to increment and the current/starting position.
    The field to increment must be of type integer.

    Next we wrote a plugin that hooked into the Pre-Create event synchronously, check the target, get the incremental settings for this entity, make sure the property specified is not in the property bag, increment the current number and update our custom entity with the newest number.

  • CRM 4 Custom Workflow to Validate NZ Bank Account/IRD Number

    Recently we created a payroll solution which integrated with Microsoft Dynamics CRM 4, part of that was to validate the Bank Account and IRD Numbers.

    Here's a screenshot of a sample workflow. You can download the code from here.

    Workflow

    Solution contains a Util.cs class which you can use on your other projects to validate New Zealand Bank Account & IRD numbers  as well as 3 workflow activities:

    - BankAccountNumberValidator.cs
      Validates the bank account number and returns true/false (IsValid property)

    - CleanBankAccountNumber.cs
      Given a bank account number it cleans and formats it to xx-xxxx-xxxxxxx-xxxx

    - IRDNumberValidator.cs
      Validates the ird number and returns true/false (IsValid property)

    Enjoy, keep and eye out for more CRM goodies...

  • CRM 4 FilteredViews, LINQ & WCF

    We decided to use FilteredViews instead of FetchXml for an internal project, but we ran into couple of problems. You can't access data from the FilteredViews using ASP.NET since it runs under NETWORK SERVICE (by default (app pool)), FilteredViews filter the data by Users.

    If you set the <identity> settings on the WCF service you'll notice it has no effect, you need to tell WCF to run in asp compatibility mode, check this link for more details.

    Impersonation needed for FilteredViews
    - EXECUTE AS doesn't work, some forums suggested we enable DB_CHAINING, TRUSTWORTHY & grant NETWORK SERVICE Impersonate for each User, we decided to take a different route since these database changes are unsupported by Microsoft.

    - Configuring the Application Pool to run as a different user gave a "Service Unavailable" error, changing the User that runs when an anonymous request comes into IIS didn't seem to work either.

    Solution
    web.config
    <authentication mode="Windows" />
    <identity impersonate="true" userName="..." password="..."/>
    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
    </system.serviceModel>

    *.svc.cs
    Set this attribute on your service class
    [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]

    That'll allow you to use FilteredViews in your asp.net application, as you can see there are downsides to this solution. Impersonating username/password is inside the web.config file (unencrypted), only allows us to filter by that user.

    Check out LinqtoCRM on codeplex, this tool will be great once all the LINQ funtionality is implemented.

  • MPEG Header Reader

    A while back I needed to read a mpeg file and retrieve the video/audio information. I didn't want to read the mpeg specification to write one from scratch so after googling around I found a project on sourceforge called mpgtx, it's written in C and has a lot of features. I didn't convert everything in mpgtx to C#, just the bits that read the mpeg header.

    Here it is for anyone else that wants to read an mpeg file using C#.