Thu
Oct 19
2006

Hide property from the Visual Studio Designer

[Browsable(false), DesignerSerializationVisibility(
                            DesignerSerializationVisibility.Hidden)]
Tue
Oct 17
2006

Web Project Errors

When opening a web project:

The project you are trying to open is a Web project. You need to open it by specifying its URL path.

Create a file called c:\inetpub\wwwroot\Folder\MyProject.csproj.webinfo and add:

<VisualStudioUNCWeb>
    <Web URLPath = "http://localhost/Folder/MyProject.csproj" />
</VisualStudioUNCWeb>

More information

Sat
Oct 14
2006

Books to Check out

Agile Principles, Patterns and Practices in C# (Robert C Martin)
Applying UML and Patterns (Craig Larman)
The Pragmatic Programmer: From Journeyman to Master (Andrew Hunt, David Thomas)
Hibernate in Action (Bauer, King)
Effective Use of Microsoft Enterprise Library (Len Fenster)
- Books on effective unit testing
Refactoring (Martin Fowler)
The Humane Interface (Jef Raskin)

Sat
Oct 14
2006

.Net Articles

The Cost of GUIDs as Primary Keys
Creating and opening ASP.NET projects in Visual Studio .NET
VSS and Visual Studio .NET Information: Bindings, suo file, vss files explained.
Dispose, Finalization, and Resource Management

Thu
Oct 5
2006

Double.NaN Equality

Console.WriteLine(double.NaN.Equals(double.NaN)); // True
Console.WriteLine(double.NaN == double.NaN); // False
Tue
Sep 19
2006

Removing double.NaN from a SQL table

SQL Server’s float datatype does not support the double.NaN value. SQL and T-SQL will prevent these values from entering the database, but ADO.Net does not. Query Analyzer will stop displaying additional results once it hits a NaN value. Enterprise manager will display -1.#IND. Normal queries on this value will result in errors so it is difficult to remove them. The solution: convert to a string first.

UPDATE mytable
SET floatColumn = NULL
WHERE cast(floatColumn AS varchar(100)) = '-1.#IND'
Sat
Jul 1
2006

Custom Configuration Section (.Net 2.0)

To add a custom configuration section to a project:

  • Add a reference to System.Configuration.dll
  • Add to your app.config:
    <configuration>
      <configSections>
        <section name="myConfiguration"
           type="MyProject.MyConfiguration, MyProject" />
      </configSections>
      <myConfiguration
        emailTo="MyEmailAddress@domain.com"
      />
    </configuration>
  • Add the class MyConfiguration.cs:

    using System;
    using System.Configuration;
     
    namespace MyProject
    {
        class MyConfiguration : ConfigurationSection
        {
            public static MyConfiguration Current
            {
                get { return ConfigurationManager.GetSection("myConfiguration") 
                                  as MyConfiguration; }
            }
     
            [ConfigurationProperty("emailTo")]
            public string EmailTo
            {
                get { return (string)this["emailTo"]; }
                set { this["emailTo"] = value; }
            }
     
        }
    }
  • To use in code:
    Trace.WriteLine(MyConfiguration.Current.EmailTo);
Fri
Jun 30
2006

Quick XML Serialization

public void SaveXml(string filename)
{
    XmlSerializer xml = new XmlSerializer(this.GetType());
    using (FileStream fs = new FileStream(filename, FileMode.Create))
    {
        xml.Serialize(fs, this);
    }
}
 
public static Accounts LoadXml(string filename)
{
    XmlSerializer xml = new XmlSerializer(typeof(Accounts));
    FileInfo f = new FileInfo(filename);
    if (!f.Exists || f.Length == 0)
        return new Accounts();
    using (FileStream fs = new FileStream(filename, FileMode.Open))
    {
        return (Accounts)xml.Deserialize(fs);
    }
}
Sun
Jun 25
2006

Syntax Highlighting in WordPress

Syntax highlighting with iG:Syntax Hiliter is mostly working now. This is the best excuse for hosting my own WordPress installation. I’ve found a few tweaks are needed to get this going:

  • I am not using a WYSIWYG editor. This is the biggest problem so far. The built-in rich editor collapses whitespace in my code so you lose indentation. I have been experimenting with other editors.
  • Updated the .syntax_hilite style in syntax_hilite_css.css with text-align:left since my current theme uses justified text. Also removed the fixed width statements.
  • Tweaked the C# color scheme to match Visual Studio.
Sun
Jun 25
2006

Redirect Trace Messages to a TextBox

///
/// Outputs trace messages to a textbox. To use call
/// Trace.Listeners.Add(new TextBoxTraceListener(textBox1).
/// All subsequent calls to Trace.WriteLine() are copied
/// to textBox1.
///
public class TextBoxTraceListener : TraceListener
{
    private TextBox textBox;
 
    ///
    /// Constructor
    ///
    public TextBoxTraceListener(TextBox p_textBox)
    {
        textBox = p_textBox;
    }
 
    ///
    /// Write a message to the textbox
    ///
    public override void Write(string message)
    {
        textBox.Text += message.Replace("\n", "\r\n");
    }
 
    ///
    /// Write a message with newline to the textbox
    ///
    ///<param name="message" />
    public override void WriteLine(string message) 
    { 
        this.Write(message + "\n"); 
    } 
}

« Newer PostsOlder Posts »

© 2009 Brian Low. All rights reserved.