Blog ( Of Ryan Olshan)

News

About Ryan Olshan

LinkedIn Profile

Follow Ryan via twitter

Join StrongTypes - Free Generics Help By Email
Join StrongTypes

Community Credit Winner

View my MVP profile

The posts on this weblog are provided "as is" with no warranties and confer no rights. The opinions expressed herin are my own personal opinions and do not represent my employer's view in any way.

Subscribe to Rolog via My AOL
Subscribe to Rolog via Bloglines


Subscribe to Rolog via Feedburner

Furl Rolog




Subscribe to Rolog via Newsburst


Subscribe to Rolog via Pluck

Add Rolog to Technorati Favorites




Thycotic Secret Server

Receive Email Updates


.NET Websites

  • => StrongTypes.com <=
  • Community Credit
  • DotNetCharity.com
  • DotNetSlackers
  • EasyListBox
  • LearnAsp.com
  • SystemNetMail.com
  • SystemWebMail.com

Blogroll

  • Alex Campbell
  • Carlos Magalhaes
  • Charles Carroll
  • Chris Taylor
  • Darren Neimke
  • David Betz
  • Eric Smith
  • Rob Caron
  • Rob Howard
  • Sam Gentile
  • Scott Guthrie
  • Scott Mitchell
  • Tess
  • Wesner Moise
  • Jason Alexander
  • Bill Ryan
  • Steve Smith
  • Sahil Malik
  • David Silverlight

Other Websites

  • 911 Pigeon Alert
  • Pacific Wildlife Project

Strong Coder Bloggers

  • Dean Fiala
  • Doug Nelson
  • Kevin Jones

Yahoo! Groups

  • => StrongTypes <=
  • AspNet2
  • AspNet20GridView
  • PayPalDevDotNet
  • RubyOnRails
  • VSTS

.NET Misc.

Where did all that new stuff in System.Globalization go?

I just answered a question online where somebody was wondering where CulturalAndRegionalInfoBuilder was. They had included a reference to System.Globalization, but still no luck. In order to access CulturalAndRegionalInfoBuilder and a lot of the new objects in System.Globalization, you need to add a reference to sysglobl.

> Right-click the project in Solution Explorer and select Add Reference .

> On the .NET tab, select sysglobl and click OK .

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Jun 07 2006, 01:08 PM by Ryan Olshan | with no comments
Filed under:
IEnumerable<> and IEnumerable

I've answered this 2x in the past week, so I think it's a worthy point to bring up. When implementing generic interface IEnumerable<>, you'll need to implement both IEnumerable<>.GetEnumerator() and IEnumerable.GetEnumerator() as IEnumerable<> inherits IEnumerable. Otherwise, you'll get the below error message:

'xxx' does not implement interface member 'System.Collections.IEnumerable.GetEnumberator()'. 'xxx' is either static, not public, or has the wrong return type.

As for why IEnumerable<> inherits IEnumerable, the best answer I could come up with is because it can.

So, to sum things up:

using System.Collections;

using System.Collections.Generic;

 

public class MyClass : IEnumerable

{

    public IEnumerable GetEnumerator()

    {

        // Code here

    }

 

    public IEnumerable GetEnumerator()

    {

        // Code here

    }

}

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: May 08 2006, 12:46 PM by Ryan Olshan | with 5 comment(s)
Filed under:
.NET Languages Galore

Ever wonder what all the .NET Languages are? See them all as well as links to learn more about them.

.NET Languages - Resources

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Apr 01 2006, 04:11 PM by Ryan Olshan | with no comments
Filed under:
Countdown to ASP.NET 2.0 Unleashed

I thought it would be cool to put together a countdown to the release of ASP.NET 2.0 Unleashed , by Stephen Walther, on June 9, 2006. So, I created the below dynamic image. Cool, huh?

Now here's the code to the above countdown image.

<% @ Page Language ="C#" %>

<% @ Import Namespace ="System.Drawing" %>

<% @ Import Namespace ="System.Drawing.Imaging" %>

<% @ Import Namespace ="System.IO" %>

<% @ Import Namespace ="System.Text" %>

 

< script runat ="server">

    protected void Page_Load( object sender, EventArgs e)

    {

        bool fontSizeParse;

        int fontSize;

        string fontSizeText = Request.QueryString[ "FontSize" ];

 

        fontSizeParse = int .TryParse(fontSizeText, out fontSize);

        if (!fontSizeParse || fontSize <= 0)

        {

            fontSize = 14;

        }

 

        string countDownDate = Request.QueryString[ "Date" ];

 

        if (! String .IsNullOrEmpty(countDownDate))

        {

            string countdownText = GetCountdownText(countDownDate);

            GenerateCountdownBitmap(fontSize, "Verdana" , Color .Black, Color .White, countdownText);

        }

    }

 

    private void GenerateCountdownBitmap( int fontSize, string fontName, Color fontColor, Color backgroundColor, string text)

    {

        Response.Expires = 0;

 

        Bitmap bitmap = null ;

        Graphics graphic = null ;

 

        try

        {

            Font font = new Font (fontName, fontSize);

 

            bitmap = new Bitmap (1, 1, PixelFormat .Format32bppArgb);

 

            graphic = Graphics .FromImage(bitmap);

            SizeF size = graphic.MeasureString(text, font);

 

            int height = ( int )size.Height;

            int width = ( int )size.Width;

 

            graphic.Dispose();

            bitmap.Dispose();

 

            bitmap = new Bitmap (width, height, PixelFormat .Format32bppArgb);

            graphic = Graphics .FromImage(bitmap);

 

            graphic.FillRectangle( new SolidBrush (backgroundColor), new Rectangle (0, 0, width, height));

 

            graphic.DrawString(text, font, new SolidBrush (fontColor), 0, 0);

 

            MemoryStream memoryStream = new MemoryStream ();

            bitmap.Save(memoryStream, ImageFormat .Gif);

 

            Response.ClearContent();

            Response.ContentType = "image/gif" ;

            Response.BinaryWrite(memoryStream.ToArray());

            Response.End();

        }

        finally

        {

            if (graphic != null )

            {

                graphic.Dispose();

            }

 

            if (bitmap != null )

            {

                bitmap.Dispose();

            }

        }

    }

 

    private string GetCountdownText( string futureDate)

    {

        TimeSpan countdown = GetCountdownTicks(futureDate);

 

        StringBuilder countdownText = new StringBuilder ();

 

        int countdownDays = countdown.Days;

        if (countdownDays == 0 || countdownDays > 1)

        {

            countdownText.AppendFormat( "{0} Days " , countdownDays);

        }

        else

        {

            countdownText.AppendFormat( "{0} Day " , countdownDays);

        }

 

        int countdownHours = countdown.Hours;

        if (countdownHours == 0 || countdownHours > 1)

        {

            countdownText.AppendFormat( "{0} Hours " , countdownHours);

        }

        else

        {

            countdownText.AppendFormat( "{0} Hour " , countdownHours);

        }

 

        int countdownMinutes = countdown.Minutes;

        if (countdownMinutes == 0 || countdownMinutes > 1)

        {

            countdownText.AppendFormat( "{0} Minutes " , countdownMinutes);

        }

        else

        {

            countdownText.AppendFormat( "{0} Minute " , countdownMinutes);

        }

 

        int countdownSeconds = countdown.Seconds;

        if (countdownSeconds == 0 || countdownSeconds > 1)

        {

            countdownText.AppendFormat( "{0} Seconds " , countdownSeconds);

        }

        else

        {

            countdownText.AppendFormat( "{0} Second " , countdownSeconds);

        }

 

        int countdownMilliseconds = countdown.Milliseconds;

        if (countdownMilliseconds < 1 || countdownMilliseconds > 1)

        {

            countdownText.AppendFormat( "{0} Milliseconds" , countdownMilliseconds);

        }

        else

        {

            countdownText.AppendFormat( "{0} Millisecond" , countdownMilliseconds);

        }

 

        return countdownText.ToString();

    }

 

    private TimeSpan GetCountdownTicks( string futureDate)

    {

        bool futureDateParse;

        DateTime futureDateParsed;

        TimeSpan ? ticksDifference = null ;

 

        futureDateParse = DateTime .TryParse(futureDate, out futureDateParsed);

 

        if (futureDateParse)

        {

            DateTime currentDate = DateTime .Now;

 

            if (currentDate < futureDateParsed)

            {

                long currentDateTicks = DateTime .Now.Ticks;

                long futureDateTicks = DateTime .Parse(futureDate).Ticks;

                long longDifference = futureDateTicks - currentDateTicks;

 

                ticksDifference = TimeSpan .FromTicks(longDifference);

            }

        }

 

        return ticksDifference ?? TimeSpan .Zero;

    }

script >

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Mar 25 2006, 10:29 PM by Ryan Olshan | with no comments
Filed under:

Some people may not know that .NET 2.0 provides APIs for accessing everything in a configuration file. The most common question I see relates to accessing the mail settings in the system.net node programmatically.

C#

using System.Configuration;

using System.Web.Configuration;

using System.Net.Configuration;

 

Configuration configurationFile = WebConfigurationManager .OpenWebConfiguration( "PathToConfigFile" );

 

MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup( "system.net/mailSettings" ) as MailSettingsSectionGroup ;

 

if (mailSettings != null )

{

    int port = mailSettings.Smtp.Network.Port;

    string host = mailSettings.Smtp.Network.Host;

    string password = mailSettings.Smtp.Network.Password;

    string username = mailSettings.Smtp.Network.UserName;

}

VB.NET

Imports System.Configuration

Imports System.Web.Configuration

Imports System.Net.Configuration

 

Dim configurationFile As Configuration = WebConfigurationManager.OpenWebConfiguration( "PathToConfigFile" )

 

Dim mailSettings As MailSettingsSectionGroup = configurationFile.GetSectionGroup( "system.net/mailSettings" )

 

If Not mailSettings Is Nothing Then

    Dim port As Integer = mailSettings.Smtp.Network.Port

    Dim host As String = mailSettings.Smtp.Network.Host

    Dim password As String = mailSettings.Smtp.Network.Password

    Dim username As String = mailSettings.Smtp.Network.UserName

End If

Share this post: | | | | |
Posted: by Ryan Olshan | with
Filed under: , ,
The bible of all debug blog sites

I'm working on a tough web site debugging issue, and somebody sent me the below link to Tess's blog. It is the best debug blog I've ever seen.

If broken it is, fix it you should

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Feb 08 2006, 12:39 PM by Ryan Olshan | with 1 comment(s)
Filed under: ,
Creating a List of a custom class

Let's say for instance, you want to create a List of your own class, say Employee, where Employee represents an employee. First, we'll start by creating an employee class.

[ Serializable ]
public class
Employee
{
    private bool m_IsSalaried;
    private int m_Age;
    private string m_Email;
    private string m_Name;

    public Employee( bool isSalaried, int age, string email, string name)
   {
      m_Age = age;
      m_Email = email;
      m_IsSalaried = isSalaried;
      m_Name = name;
   }

    public int Age
   {
       get { return m_Age; }
       set { m_Age = value ; }
   }

    public string Email
   {
       get { return m_Email; }
       set { m_Email = value ; }
   }

    public bool IsSalaried
   {
       get { return m_IsSalaried; }
       set { m_IsSalaried = value ; }
   }

    public string Name
   {
       get { return m_Name; }
       set { m_Name = value ; }
   }
}

You can then add an employee to a List collection as follows:

using System.Collections.Generic;

...

List < Employee > m_EmployeeList = new List < Employee >();
m_EmployeeList.Add( new Employee ( true , 30, , "Jane Doe" ));

You can get values for Employees in the List collection by enumerating through the Employees.

foreach ( Employee employee in m_EmployeeList)
{
   SomeBool = employee.IsRetired;
   SomeInt = employee.Age;
   SomeString1 = employee.Email;
   SomeString2 = employee.Name;
}

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Jan 11 2006, 10:05 AM by Ryan Olshan | with no comments
Filed under: , ,
Interesting code standard blog entry

Today I came across an interesting blog entry debating the use of prefixing m_ to a variable name when naming private member variables. I feel that if there was a standard, we would all be following it. IMO, if you develop a decent coding standard, you should be able to create code that reads like a book without the need for comments, with the exception of explaining something such as an edge case (i.e. We must set VariableName to 0, else NullReferenceException will be thrown).

m Underscore

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Jan 04 2006, 11:36 AM by Ryan Olshan | with no comments
Filed under:
What will upgrading my .NET 1.x project to 2.0 break?
If you have a .NET 1.x project and are thinking about upgrading it to 2.0, take a look at Breaking Changes in .NET 2.0 Framework first, as there is a comprehensive listing of changes that could break your application upon upgrade.
Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Dec 27 2005, 12:22 PM by Ryan Olshan | with no comments
Filed under:
Running different versions of the same assembly

I came across a thread on one of my lists today in which somebody was having problems running 2 different versions of the FreeTextBox assembly in the same /bin directory. The answer to this one is pretty simple. You need to install all versions of the assembly with the GAC (Global Assembly Cache). To do so, you need to change to the directory of each assembly using the command prompt and then run the following command: gacutil /i AssemblyName.dll , where AssemblyName.dll is the name of the assembly. After all versions are installed in the GAC, they are then shared and thus you do not need to keep them in the /bin directory to use them.

R

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Dec 19 2005, 08:02 PM by Ryan Olshan | with no comments
Filed under:
More Posts