blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Merrick Chaffer's Blog

  • ASPNET_REGIIS.exe problems installing ASP.NET

    Recently I had an issue where aspnet_regiis.exe -i was not updating the home directory configuration for my web root in Windows XP SP2.

    To resolve this I used the following commands, suggested by my colleague Mark Mann, instead to first remove all script maps to any version of ASP.NET from the specified path recursively, and then reinstall them.

    C:\Inetpub\AdminScripts>aspnet_regiis.exe -k W3SVC/1/ROOT
    Start removing any version of ASP.NET DLL recursively at W3SVC/1/ROOT.
    Finished removing any version of ASP.NET DLL recursively at W3SVC/1/ROOT.

    C:\Inetpub\AdminScripts>aspnet_regiis.exe -s W3SVC/1/ROOT
    Start registering ASP.NET scriptmap (2.0.50727) recursively at W3SVC/1/ROOT.
    Finished registering ASP.NET scriptmap (2.0.50727) recursively at W3SVC/1/ROOT.

    This can be confirmed in inegmgr, by looking at the home directory configuration for your default web site.

    image

    image

  • Insert tracepoint in Visual Studio for Debug.WriteLine alternative

    For those who like me didn’t know about this hidden gem:

    You can now set Tracepoints instead of just Breakpoints in VS2008. Here’s the difference between the two as described on MSDN:

    “Breakpoints tell the debugger that an application should break, pause execution, at a certain point. When a break occurs, your program and the debugger are said to be in break mode. For more information, see Breaking Execution.

    Tracepoints are a new debugger feature in Visual Studio. A tracepoint is a breakpoint with a custom action associated with it. When a tracepoint is hit, the debugger performs the specified tracepoint action instead of, or in addition to, breaking program execution.”

    To set a Tracepoint, right-click on the line of code you want to debug, go to Breakpoint > Insert Tracepoint. In the breakpoint dialog below, you will be able to specify a message to print each time the tracepoint is hit. This is a handy way of having debug trace to output variable values without littering your code with “Debug.WriteLine” all over.

    Cheers

    Pascal

    tracepoint

  • Hacking visual studio to use greater than 2GB of memory

  • Code coverage in Visual Studio 2008 using Test driven .NET and Team Coverage

    A colleague of mine this week showed me his code coverage as being over 94% for his production code, which impressed me so much, it spurred me on to ensure that all code paths in my code from now on go blue instead of red when testing with Team coverage, using the Test driven .NET addin for visual studio 2008. Not sure what I'm on about, then follow the steps below to get up to speed...

    1. Install Test driven .NET version 2.12.2179 from here http://www.testdriven.net/download_release.aspx?LicenceType=Personal
    2. Once installed ensure the Test driven .net addin is available from Tools, Addins in visual studio
      Picture showing addin manager
    3. In your unit test files, simply click anywhere outside of a code block, and select the Test with -> Team coverage from the right click context menu
      Test with team coverage option
       
    4. Keep an eye after the tests have run on the output window, as the test results window will not actually be updated by running this context menu option, so you'll need to look here to see how many of your tests actually passed.
      Output window
    5. Then click on the show coverage colour option on the test toolbar
      Show Code coverage coloring
    6. Now you will see what areas of your code are covered. Blue background is covered, orange is partially covered (this is like when you have a two condition if statement and the unit test has only satisfied on of the conditions to get passed it), and red is not covered at all.
      Code coverage highlighting
    7. Another option for a summary view is to look at the Code Coverage Results window which should appear after the unit testing is complete, and sort by any of the column headers, or simply drill down to the code you wrote to see if it is covered fully. In the example below you'll see that I had 91.67% coverage on the code I wrote, anything over 90% is pretty good going in my opinion.
      Code coverage results window

       
  • Using linq in your C# code

    Just came across a nasty gotcha today, where by we were trying to use the new C# 3.5 syntax

    var x = from item in items select new Item { ItemName = item.Name };

    and getting a compile error. Turns out this was due to the need to have the following using statement (that doesn't come up in a smart tag prompt when you're writing linq),

    using System.Linq;

    To be fair the compiler error was suggesting exactly this.

  • Daylight savings issue with MOSS 2007 deployments pre SP1

    Daylight savings time.

    http://blogs.msdn.com/sharepoint/archive/2007/10/09/important-security-hotfix-ms07-059.aspx

    When the clocks went forward or back this weekend, this stopped sharepoint deployment from working for many sharepoint customers in the UK.

  • EMC to acquire Conchango

    News announced yesterday that EMC are to acquire Conchango.

  • Customising file upload validation in MOSS 2007 (Sharepoint)

    Just spent the day trying to do this, having not really written sharepoint code before. Seeing as it took most of the day to figure out, and perfect, I thought I would post the solution in case I ever needed to repeat this again...

    clip_image002[5]

    In the customised UploadAtlasDocument.aspx in the 12 hive C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\ I added the following code...

    <script runat="server">

     

        /// <summary>

        /// Validates the posted filename doesn't already exist in the sharepoint list CH Documents

        /// </summary>

        /// <param name="source"></param>

        /// <param name="args"></param>

        void custVldFileExists_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)

        {

            //note you don't get intellisense for this.OverwriteSingle

            //as it is nested in a template control

            if (!string.IsNullOrEmpty(args.Value)

                && this.OverwriteSingle.Visible == true

                && this.OverwriteSingle.Checked == false)

            {

                FileInfo fileInfo = new FileInfo(this.InputFile.PostedFile.FileName);

     

                string newFileName = fileInfo.Name;

     

                using (SPSite site = new SPSite(SPContext.Current.Web.Url))

                {

                    using (SPWeb webSite = site.OpenWeb())

                    {

                        SPList chDocumentsList = webSite.Lists["CH Documents"];

                       

                        //do we have any files existing in the list already

                        if (chDocumentsList != null && chDocumentsList.RootFolder.Files.Count > 0)

                        {

                            //we have files in the list already

                            //so iterate round each one and see if the one we're about to upload

                            //already exists in the list.

                            foreach (SPFile spFile in chDocumentsList.RootFolder.Files)

                            {

                                if (string.Compare(spFile.Name, newFileName, StringComparison.InvariantCultureIgnoreCase) == 0)

                                {

                                    //the file name we're uploading

                                    //matches an existing file,

                                    //and the user hasn't checked the OverwriteMultiple check box

                                    //so invalidate this validator

                                    //in order to get message back to the user.

                                    args.IsValid = false;

                                    break;

                                }

                            }

                        }

                       

                        webSite.Close();

                    }

                    site.Close();

                }

            }

        }

    </script>

    ...

    <TR><TD>

                <wssawc:InputFormRequiredFieldValidator ID="InputFormRequiredFieldValidator1" ControlToValidate="InputFile"

                   Display="Dynamic" ErrorMessage="Please click the browse button to upload a file." Runat="server"

                   BreakBefore="false" BreakAfter="false" EnableClientScript="false" />

                <asp:CustomValidator ID="custVldFileExists" runat="server"

                        ErrorMessage="File already exists. Please either rename the file or select overwrite to replace the existing file."

                        ControlToValidate="InputFile" OnServerValidate="custVldFileExists_ServerValidate"

                        Display="Static" EnableClientScript="false" ></asp:CustomValidator>

                <asp:CustomValidator ID="CustomValidator1" ControlToValidate="InputFile"

                   Display = "Dynamic"

                   ErrorMessage = "<%$Resources:wss,upload_document_file_invalid%>"

                   OnServerValidate="ValidateFile"

                   runat="server" EnableClientScript="false" />

                                  </TD></TR>

    Note the EnableClientScript="false" was required so that the error would get cleared from our custom validator if the user deleted the text out of the input file control, and then hit OK again.

  • Resetting %ERRORLEVEL% in batch file programming

    Came across a definite gotcha today in batch file programming, when I noticed that we had SET ERRORLEVEL=0 in one of our batch files. Turns out that once you set this variable explicitly then any command you run after will not be able to change the value of the %ERRORLEVEL% variable. E.G.

    C:\>dir AUTOEXEC.BAT
    Volume in drive C has no label.
    Volume Serial Number is 907A-1111

    Directory of C:\

    02/08/2006  09:58                 0 AUTOEXEC.BAT
                   1 File(s)              0 bytes
                   0 Dir(s)  11,104,747,520 bytes free

    C:\>echo %errorlevel%
    0

    C:\>dir lkksjdfljsdk
    Volume in drive C has no label.
    Volume Serial Number is 907A-1111

    Directory of C:\

    File Not Found

    C:\>echo %errorlevel%
    1

    C:\>set errorlevel=0

    Now you would expect the next rogue dir statement to set the errorlevel back to 1

    C:\>dir lkksjdfljsdk
    Volume in drive C has no label.
    Volume Serial Number is 907A-1111

    Directory of C:\

    File Not Found

    But as you can see it does not

    C:\>echo %errorlevel%
    0

    A neat way to reset the error level is to just use the verify >nul command, as this works fine

    C:\>dir sdkfljs
    Volume in drive C has no label.
    Volume Serial Number is 907A-1111

    Directory of C:\

    File Not Found

    C:\>echo %errorlevel%
    1

    C:\>verify >nul

    C:\>echo %errorlevel%
    0

    C:\>dir lskjlkj
    Volume in drive C has no label.
    Volume Serial Number is 907A-1111

    Directory of C:\

    File Not Found

    C:\>echo %errorlevel%
    1

    C:\>

  • New windows live writer

    Have just upgraded my msn messenger this morning, and noticed that it now comes with a suite of other tools such as windows live writer for blogs. Using it now in fact to write this blog, but having difficulty figuring out how to get that nice intellisense for our conchango tags.

    <LATER>

    Just realised that our tags are accessible from the bottom of the windows live writer window, as categories in the Select categories drop down.

  • Customising sharepoint error page using HttpModule

    Ensure that your HttpModule is inserted in the web.config above the declaration for the SPRequest sharepoint http module, otherwise you'll always be redirected to the sharepoint error page.

    When debugging your module you may come across an error message like Headers have already been written otherwise.

    jimbowen

  • XPath and Namespaces (and msbuild sdc xml.modifyfile task)

    xmlDocument.SelectNodes with xmlns="..."

    Spent most of today wondering why I couldn't update a connection string in a web.config file using xpath which had the default namespace for xmlns  defined at the root of the config file. e.g. <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

    Turns out that you have to add a XmlNamespaceManager to your document.SelectNodes xpath query, which has had a prefix added to it first, and alter your xpath to include these prefix.

    E.g.

    xmlNamespaceManager.AddNamespace("ns", xmlDocument.DocumentElement.NamespaceURI)

    then

    doc.SelectNodes("/ns:configuration/ns:connectionStrings") - will actually work.

    The funny thing is after figuring all this out for myself, a colleague suggested that we simply use the Xml.ModifyFile task in the Microsoft SDC tasks, which happens to cope for this sort of thing within the file. It also appears as if someone has come across this problem before as well...

    http://www.codeplex.com/sdctasks/Thread/View.aspx?ThreadId=13167

    another very concise reference if you're using .net directly to update documents using xpath queries is below...

    http://msdn2.microsoft.com/en-us/library/ms950779.aspx (checkout the examples towards the middle of this page that show that you should expect NO RESULTS if you do not prefix your xpath).

    SAVING without xmlns="" appearing on your element node

    To get a document element created without the extra xmlns="" appearing as an attribute in your newly created element, you must use the 3rd overload as follows ..

    xmlDocument.CreateElement("", "myNodeName", xmlDocument.DocumentElement.NamespaceURI)

  • Returning an ERRORLEVEL to DOS prompt from OSQL utility

    After much trial and tribulation today I've finally cracked how to return a non zero exit code from a call to osql back to a dos batch file.

    The answer is as follows. Note the bits in bold below are most important, and the use of the single & sign to denote running the IF ERRORLEVEL 1 command even if the previous osql command errors.

     

    for /F %%i in ('dir *.sql /b') do osql -b -E -S MyServer\InstanceName -d MyDatabase -i %%i & IF ERRORLEVEL 1 goto ABORTBATCH

    :ABORTBATCH
    popd
    @echo on
    REM Specify non zero exit code to signal error occurred
    exit /b 1

  • Visual Studio 2008 and .NET 3.5 Released

    For a blog detailing all the new features with.NET3.5 and Visual studio 2008, including javascript intellisense and //<reference> syntax,check out Scott Gu's blog post here.

     http://weblogs.asp.net/scottgu/archive/2007/11/19/visual-studio-2008-and-net-3-5-released.aspx

  • Extension methods in .NET3.5 and LINQ

    Was just reading on Scott Gu's blog about the release of Visual Studio 2008 and .NET 3.5, and came across an excellent description of the new extension methods feature in .Net 3.5. I have to say that until I saw this blog post, the quick overview from Mike Taulty at TechEd lost me somewhat as to what the purpose of these extension methods is, and also how they apply to LINQ...

    http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx

More Posts Next page »
Powered by Community Server (Personal Edition), by Telligent Systems