Sat
Dec 30
2006

Disable Infragistics WebGrid

To simulate a disabled grid:

Grid.Bands(0).RowStyle.BackColor = Color.LightGray
Grid.Bands(0).RowStyle.ForeColor = Color.DarkGray
Grid.Bands(0).RowAlternateStyle = Grid.Bands(0).RowStyle
Grid.Bands(0).SelectedRowStyle = Grid.Bands(0).RowStyle
Grid.Bands(0).HeaderStyle.ForeColor = Color.DarkGray
Grid.BackColor = Color.LightGray
Grid.DisplayLayout.ClientSideEvents.BeforeSelectChangeHandler = "Grid_BeforeSelectChange"
Grid.DisplayLayout.ClientSideEvents.BeforeRowActivateHandler = "Grid_BeforeRowActivate"

Add to aspx:

  <script language="javascript">
    // Prevent the user from changing the currently active row
    function Grid_BeforeRowActivate(gridName, id)
    {
        igtbl_cancelPostBack(gridName);
        return 1;
    }
    // Prevent the user from changing the currently selected row
    function Grid_BeforeSelectChange(gridName, id)
    {
        igtbl_cancelPostBack(gridName);
        return 1;
    }
    </script>

To restore:

Grid.Bands(0).RowStyle = Grid.DisplayLayout.RowStyleDefault
Grid.Bands(0).RowAlternateStyle = Grid.DisplayLayout.RowAlternateStyleDefault
Grid.Bands(0).SelectedRowStyle = Grid.DisplayLayout.SelectedRowStyleDefault
Grid.Bands(0).HeaderStyle = Grid.DisplayLayout.HeaderStyleDefault
Grid.BackColor = Color.Transparent
Grid.DisplayLayout.ClientSideEvents.BeforeSelectChangeHandler = ""
Grid.DisplayLayout.ClientSideEvents.BeforeRowActivateHandler = ""
Fri
Oct 27
2006

Redirect Tracing to a File

<system.diagnostics> 
	<trace autoflush="true" indentsize="4"> 
			<listeners> n
			<add 	name="FileListener" 
				type="System.Diagnostics.TextWriterTraceListener" 
				initializeData="TraceLog2.txt" /> 
		</listeners> 
	</trace> 
</system.diagnostics>
Wed
Oct 25
2006

Detect Password Expiry

See the original Usenet posting.

public static DateTime PasswordExpirationDate(string user, string domain)
{
	string connect = String.Format("WinNT://{0}/{1},user", domain, user);
	DirectoryEntry entry = new DirectoryEntry(connect);
 
	if (entry == null)
		Console.WriteLine("Failed to get Directory Entry.");
 
	int secondsRemaining = (int)entry.Properties["MaxPasswordAge"][0];
 
	// A policy setting of -1 means no expiration,
	// so return an 'infinite' date
	if (secondsRemaining > 0) 
	{
		secondsRemaining -= (int)entry.Properties["PasswordAge"][0];
		return DateTime.Now.AddSeconds(secondsRemaining);
	} 
	else 
	{ 
		return DateTime.MaxValue; 
	}
}
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

.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);
    }
}

« Newer PostsOlder Posts »

© 2009 Brian Low. All rights reserved.