Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Summary
Great tips for .NET developers.
Description

Test for already running EXE
How can you tell if an EXE (or any process) is currently running? By using the Process class of the System.Diagnostics namespace:
using System.Diagnostics;

// Creates an array of all running processes
Process[] runningProcesses = Process.GetProcesses();

// Creates an array of all instances of one specific process
Process[] wordInstances = Process.GetProcessesByName("winword");

// If you know the specific ID, you can use the following to get the process
// but this isn't good for simply checking if the process is running
// because it crashes if the process is NOT running.
Process myProcess = Process.GetProcessById( ... );

from a solution provided by Çetin Basöz in Message #1221521

Reading a Delimited Text File
The following code illustrates how to read a comma-delimited file into a DataTable.
    string colString;
    string[] strItems;
    DataRow dr;
    TextReader tr;
    try
    {
        string filePath = @"c"\MyFile.txt";
        tr = File.OpenText(filePath);

        colString = tr.ReadLine();
        while(colString != null)
        {
             strItems = colString.Split(",".ToCharArray());

             dr = MyTable.NewRow();
             dr["col1"] = strItems[0];
             dr["col2"] = strItems[1];
             dr["col3"] = strItems[2];
             dr["col4"] = strItems[3];
             
             MyTable.Rows.Add(dr);

             colString = tr.ReadLine();
         }
     }
     catch(Exception e)
     {
         MessageBox.Show(e.Message);
     }

from a solution provided by John Baird in Message #1211637

Pre-Populating a Password on a Web Page
On a web page, your password TextBox has the TextMode property set to Password. But if you try to pre-populate it with an existing password by simply setting the Text property:
txtPassword.Text = "ABCD"

the password is not displayed.

In order to get this to work, you must add and set a value attribute:
txtPassword.Attributes.Add("value", "ABCD")

from a solution provided by Dmitry Litvak in Message #1211193

Closing All Child Forms
In my February 2006 Tips article, I talked about using a FormsHandler to be able to easily close all open Forms when a user shuts down your application.

However, that FormsHandler only pertained to SDI forms ... independently opened forms. If your application is using MDI forms, do the following from the Parent Form to close all Child Forms:
foreach (Form o in this.MdiChildren)
	o.Close();

from a solution provided by Bonnie Berent in Message #1172456

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers