Wednesday, November 30, 2005

Great XP tip!

Thanks to Saveen Reddy for this incredible tip for anyone working with multiple files in XP!


Windows XP comes with a built-in solution to batch rename files
· Browse Windows Exploer to the files you want to fix
· Switch to Details view (recommended, but not required)
· Order the view by time or name or size as desired
· multi-select all the files to with the names you don't like
· While the files are selected, right click on the file you want to consider as the *first* one. The context menu will appear.
· Select Rename
· The file upon which you right-clicked will now show that you can edit its name
· Change the name as desired and add a space and a starting number in parenthesis and leave the extension alone
o Example:
§ Rename "pic383718.jpg"
§ To this "My Vacation in Italy (1).jpg"
· The rest of the files will be renamed accodingly.
o Final Output
§ My Vacation in Italy (1).jpg
§ My Vacation in Italy (2).jpg
§ My Vacation in Italy (3).jpg
§ My Vacation in Italy (4).jpg
§ My Vacation in Italy (5).jpg
§ My Vacation in Italy (6).jpg
What happens if the number in parenthesis is left out? For example, if one named the first file "foo.jpg"?
The results will look like this:
· foo.jpg
· foo (1).jpg
· foo (2).jpg
· foo (3).jpg
· foo (4).jpg
· foo (5).jpg

Sunday, November 20, 2005

XBox 360 - My 2 cents

Well, it's finally here. Circuit City started taking early orders for the unit and had so many hits that their web site came to a crawl. I think that Microsoft's design, planning, marketing and especially the Timing will make a significant dent in the PlayStation holdings this time. This unit has so many features that very few articles discuss all of it. Look for a significant third party business market to emerge within 45 days. On-line communities, gaming, and the little known Media support will become common place on the unit in 90 days. Although the Media portion is not getting as much article space as it should.

Just my 2 cents worth.

Friday, November 18, 2005

OleDb - little known performance hit

I have to work with databases other than SQL Server (shocking, yes, I know), so I use the OleDb data objects quite a bit. I came across something in the MSDN that I did not know and I wanted to make sure that everyone knew about it.


Avoid Accessing the OleDbConnection.State
Property

If the connection has been opened, OleDbConnection.State property makes the native OLE DB call IDBProperties.GetProperties to the DATASOURCEINFO property set for the DBPROP_CONNECTIONSTATUS property, which may result in a round trip to the data source. In other words, checking the State property can be expensive. So only check the State property when required. If you need to check this property often, your application may perform better if you listen for the StateChange event for your OleDbConnection. For details on the StateChange event, see Working with Connection Events.





Thursday, November 17, 2005

Office 12 Beta 1

Well, it's finally here! Beta1 of Office 12. I can't wait to see what's happened in Access. If they have not made significant changes to the development model, then Access (in my mind) is a dead product. I'll keep you posted.

Monday, November 07, 2005

Convert Icon To Bitmap code snippit

Convert Icon To Bitmap code snippit:


This is just another little tip to show how easy it is to convert from an Icon to an Image.  For example, if you have an Icon and you want to show it in a PictureBox you have to convert it to a BitMap first.  This little Snippit will do it for you.


private Image ConvertIconToImage(Icon icon)
{
Bitmap b = new Bitmap(icon.Width, icon.Height,  
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(new SolidBrush(Color.Empty), new Rectangle(0, 0, b.Width, b.Height)) ;
g.DrawIcon(icon, 0, 0);
g.Dispose() ;
return b ;
}

A tip about Error Handling

Tired of coding class names or method names in your error handling calls, then don’t!  .Net provides you a very convenient way to dynamically retrieve that information.  For example, a class with typical error handling might look something like this:
 
class TypicalErrorMessage
{
  private static readonly String _className = "TypicalErrorMessage";
 
  public TypicalErrorMessage()
  {
  }
 
  public void MethodThatThrowsAnError()
  {
   String _memberName = "MethodThatThrowsAnError";
 
   try
   {
         throw new System.Exception("This is an error");
   }
   catch (Exception ex)
   {
         MessageBox.Show(String.Format("An error occurred in class {0} in member {1}.\nException: {2}",
          _className, _memberName, ex.ToString()));
   }
  }
}
 
If you change the method name and forget to change the class or member name, then it gets confusing.  Also, it gets really tedious to create this type of error message for each member.  Rather than do the above, you can do something like the following:
 
class BetterErrorMessage
{
  public BetterErrorMessage()
  {
  }
 
  public void MethodThatThrowsAnError()
  {
   try
   {
         throw new System.Exception("This is an error");
   }
   catch (Exception ex)
   {
         MessageBox.Show(String.Format("An error occurred in class {0} in member {1}.\nException: {2}",
          this.GetType().ToString(), MethodBase.GetCurrentMethod(), ex.ToString()));
   }
  }
}
 
 
As you can see, you no longer have to enter the class or member names so you could copy and past this same error handling to another method without having to change the class or method names.
 
Note: this is not an example of how to do error handling, but how to get more specific information on the circumstances of the error.
 
This is just one quick example that shows how the .Net framework is built around making it easier to build better software faster.