Because I'll forget if I don't write it down.
RSS icon Email icon Home icon
  • Intellisense not working via COM

    Posted on August 13th, 2009 Dave No comments

    I recently needed to write a class in C# that would be accessed by a VB6 application – something quite new to me.

    The existing VB6 application (which is in the process of being rewritten in C#) currently uses OLE Automation to generate MSWord documents based on templates. While this approach was working fine it was pretty slow. Having made the decision that the new version of the application would be capable of generating Word 2007 documents it was decided that the resulting class should be accessible to the VB6 application via COM Interop.
    Read the rest of this entry »

  • ASP.NET Date Validation

    Posted on May 6th, 2009 Dave 2 comments

    A simple requirement at first sight not one with a simple solution.

    You have an ASP.NET page which allows the user to specify a date which is then used as an input parameter for an SQL Stored Procedure. What is stopping the user from entering ‘Hello World’ and submitting it?

    Answer, nothing unless you configure some sort of validation.

    So what sort of validatator do you use? At first sight there does not appear to be a suitable candidate but to enforce a specific format, e.g. dd/mm/yyyy, the RegularExpressionValidator could be called into play here. This will stop the user from entering data in the wrong format but what about invalid date such as 32/12/07 or 29/02/07? How do make sure that the date is a real one?

    This is where I was a little while ago and I decided to opt for the CustomValidator, writing my own Server Side and Client Side validation functions that Cast the user input to a DateTime type and catching any exceptions.
    While this worked I was not too happy with the operation of the code. Then I watched a PodCast from dnrTV where Peter Blum demonstrated some lesser known features of the ASP.NET validator controls. He used a CompareValidator to check for a valid date – a CompareValidator??!!

    I normally associate the CompareValidator to check one value against another, e.g. Password and Confirm Password. So how does it validate a date?

    • Simply add a CompareValidator and set it’s ControlToValidate to the textbox containing the date.
    • Now locate the Operator property and Select DataTypeCheck from the dropdown list.
    • Finally set the Type property to Date and you’re done.

    So there you have it – no need for custom code on Server or Client side.

    This article was originally posted in March 2008 on my [now stagnant] DotNetNoteToSelf blog which will be deactivated in the not too distant future

  • Reading an RSS Feed with C# and Python

    Posted on May 5th, 2009 Dave No comments

    When I started this site I had a project in mind that would download Podcasts as they were posted and maintain the content of my MP3 player so that I didn’t have to do it myself. Well since then I have lost my iTunes virginity and while it doesn’t do everything that I wanted (like telling me that a new episode has been downloaded) it does automatically download and delete them once I’ve watched/listened to them.

    But just because I don’t need to develop a complete application there is still an itch to scratch here – a few of them in fact.

    • How do I download an RSS stream – it’s not just podcasts that uses them
    • How do I parse the resulting XML
    • How do I download a file and store it locally
    • and how do I do this in C# and Python

    Well this post will answer the first two questions using C# and LINQ and Python and it’s XML library.
    Read the rest of this entry »

  • Request format is unrecognized for URL unexpectedly ending in …

    Posted on April 9th, 2009 Dave No comments

    Another thing that you think would be straight forward but turned out to be quite frustrating.
    I have written Web Services in the past without any problems but recently when I was writing one specifically for Excel (2007) I could not get it to link properly.

    Running the web service in VS2005 resulted in the test page we all know and love and the Invoke button worked fine! Taking the URL and pasting it into Excel resulted in a “Request format is unrecognized for URL unexpectedly ending in…” error!

    It turns out that this is by design – sort of. Basically the HTTP Get and HTTP Post protocols are disabled by default (not the case in .NET 1.0). Enabling them in is simple matter of adding the following to the system.web section of the web.config:

    <configuration>
      <system.web>
        <webServices>
          <protocols>
           <add name="HttpGet"/>
           <add name="HttpPost"/>
          </protocols>
        </webServices>
      </system.web>
    </configuration>

    TaDa! it worked.

    If you want some more information then click here to got to the Knowledge Base article [KB819267]

  • Calling Code-Behind Method from JavaScript

    Posted on March 23rd, 2009 Dave 8 comments

    It shouldn’t be too hard should it? You want to use some Javascript on the client-side to call a method on in the Code-Behind of your aspx page – how hard can that be? Surely it must be possible.

    I was developing a DotNetNuke module (so the code below is VB.NET and not C#) which would allow the user to search for locations using Virtual Earth and store the latitude and longitude (as well as the zoom level) in a database.

    The problem is that the Virtual Earth API is a Javascript (and hence Client-Side) technology and in the normal scheme of things cannot access .NET code on the server. So how do you do it? How do you get a Javascript function to call a Server-Side method – Is it even possible?
    Read the rest of this entry »

  • Dirty Checking and the .NET GridView

    Posted on February 25th, 2009 Dave 6 comments

    Most Web Developers have come across this problem at one time or another, how do I stop someone navigating away from a page if they have not saved any changes they have made?

    The answer is that you need to employ ‘Dirty Checking’, basically set a flag when the page data is changed and check it if the user tries to navigate away. Sounds simple (and in many instances it maybe) but I have encountered a problem recently (today!) which took some thought to get around. Read the rest of this entry »