in

ASP.NET Weblogs

Matthew ".NET 247" Reynolds

Matthew Reynolds... software development consultant, author, speaker and trainer

July 2003 - Posts

  • Automated VB .NET to C# conversion

  • VS .NET 2002 Web Projects require security tweak on W2K3

    Those of you trying to develop Web Projects with Windows 2003 may run into a small security problem.  The error you get is “Unable to create Web project.  (blah blah)  The two need to map to the same server location.  HTTP error 404.”

    There is a Microsoft KB article here that explains the issue: http://support.microsoft.com/?kbid=327283

    Basically, what's happening is that VS .NET 2002 is trying to download a .tmp file.  IIS6 blocks .tmp files as default, which I assume gives rise to the 404 error.  There are two workarounds.  One - upgrade to VS .NET 2003 (thanks MS).  The other is explained in the KB article and involves mapping the .tmp file to a MIME type so that IIS6 will serve the files properly.

  • VSIP SDK now downloadable

    All those who don't want to spend $10k on a VSIP license, but do want to have integration with Visual Studio can now do so. 

    http://www.vsipdev.com/

  • Today's quickie - IE print and print preview

    For those who host IE in their own .NET applications (as I do quite often), here's a tip on how to tell IE to print the currently navigated page:

    object empty = null;

    this.axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
    SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, ref empty, ref empty);

    There are a bundle of other options in that first OLECMDID enumeration.  Enjoy!

  • Decompilation and other neat tricks

    So, how do you find out that StringBuilder doubles its capacity when it needs more space?

    For that matter, how do you find out how the Framework classes work?

    If you're serious about .NET programming, you'll often need to understand exactly how a class is doing what it's doing.  Yes OO is all about little boxes of code that we manage on the periphery, but as hardcore developers, all of us at sometime need to crack open the boxes and start pulling out wires.

    The Rotor source is really useful for certain base libraries.  Rotor doesn't cover the entire base of the BCL, but it has most classes.  Plus, as it's source you don't have the problem with decompilers (more later).

    Dave Wanta has put the Rotor source on 123ASPX.  It's here.  Try StringBuilder and look for GetNewString().  (Microsoft - seriously, no comments on your private methods?!)

    Dave - if I had one hint for you - put up a bunch of redirection pages up on your site so that we can just go to a class, e.g. http://www.123aspx.com/rotor/System/Text/StringBuilder

    The other trick is to use a decompiler.  I used to be all over Anakrino, and although I still am, I'm finding myself using the decompiler in the latest rev of Reflector.

  • Cool StringBuilder Tip (Rob McLaws)

    Rob McLaws offers a few thoughts about StringBuilder.  I've posted it here because I had a couple of things to add, and Rob's pointing out one of those classic "issues" with .NET.  The Framework often does so many useful things for us that we don't necessarily consider exactly how they work.

    By default, StringBuilder (like ArrayList) will double its capacity when it's capacity is reached.  For example, if it has 32 bytes in its internal array, when you add byte 33, the storage will be doubled to 64, then 128, then 256, and so on.  The doubling usually improves performance as there's a considerable amount of memcpy-ing going under under the covers to deal with the dynamic nature of these storage structures.

    Now imagine you're storing a large XML file in a StringBuilder.  That XML file is 1MB in size.  Add byte number 1MB+1byte, you're now using 2MB of storage.  In effect, you could end up being extremely wasteful of space.  Rob's technique here of guestimating how much capacity the builder would require is useful for a) reducing the number of operations that happen to grow the array and b) decreasing the memory footprint of the application.

    -----------------

    One of the great things about the StringBuilder is it's ability to dynamically resize itself for situations where it is dealing with large strings. It was very helpful in building GenX.NET, especially since I wasn't always going to be writing to the file system anymore. Back in the 2.0 days, each time I loaded up a new line, I wrote it to the file system, so performace wasn't really a factor. Now it is. The problem is, however, that this dynamic resizing can sometimes come at a performance hit IF you are adding to your string beyond 1000x.

    Enter StringBuilder.EnsureCapacity(Integer)

    For GenX.NET, it is quite conceivable that the StringBuilder may append new data over a million times. Well, I want to make sure that it resizes itself as few times as possible. So, before I output any data, I cycle thru the Tables, Rows, and Columns collections of the DataSet, and get a total cell count. Then, I multiply that number by 30, and I have a fairly rough approximation of how much data the StringBuilder will be holding when finished. This saves me from most of the resizing that will take place on large DataSets.

    What did it do for performance? Well, small files are returned almost instantaneously. Larger files are generated in almost half the time it took before I added that simple algorithm. I'm sure it will definitely have an effect when the server is under a heavier load too.

    So there you have it. StringBuilders run faster if you call .EnsureCapacity first.

    (Original post)

  • LocalDesktop - new rev with proxy support

    Doug Thews has just released a new rev of his LocalDesktop ASP.NET application, which is designed to be your desktop background and provide you with RSS feeds of all your favourite blogs. 

    This new rev includes support for proxies, which it didn't necessarily have before depending on how you had your ASP.NET security set up.

    Download

  • TLBIMP tip-o-the-day

    TLBIMP (the utulity for importingtype libraries into managed assemblies) allows you to define the namespace for generated classes. 

    Unlike me, try not to give TLBIMP an invalid namespace name, because it doesn't check.  e.g. you can specify Interop.MyApp.5.0.0 (as in v5.0.0).  This does generate an assembly, but you then can't use it because in code specifying, say, using Interop.MyApp.5 yields an error.

  • Command Prompt context menu item

    Very useful...

    Have you ever wanted to have a "Command Prompt" context menu item that allows you to open a DOS box at any folder location?

    While we're at it, how about if we add the Visual Studio.NET environment path variables so you can run REGASM, WINCV or any of the other VS.NET tools from that command prompt?

    Easy! Just save the following lines to a text file with a .REG extension and double-click on the saved file:


    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Command Prompt\Command]
    @="Cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio .NET\\Common7\\Tools\\vsvars32.bat\" "

    Voila! Context menu choice for a Command Prompt with VS.NET environment by simply right-clicking on any folder!

    Get the registration entry file here

    source : Peter Bromberg (eggheadcafe.com)

    [{Sudhakar's .NET Dump Yard;}]
  • Stupid .NET Trick #174/B

    Add a LinkLabel called linkGoogle to a Windows Form Form...

    Set the Text property to http://www.google.com/

    Double-click on the control...

    Add this code:

    try
    {    
         System.Diagnostics.Process.Start(linkGoogle.Text);
    }
    catch(Exception ex)
    {    
        // whatever you usually do here, e.g. MessageBox.Show(this, ex.ToString());
    }

    Et voila - link label that shows IE navigated to the given page.
More Posts Next page »