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

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

Special Characters in Files
Special characters, such as "é" or "ë" can present a problem when reading files, whether you're simply reading from a text file or needing to create a DataSet from XML. The trick is to use Encoding with a StreamReader.
// Reading a Text File
StreamReader sr = new StreamReader("MyFile.txt",Encoding.GetEncoding(1252));
textBox1.Text = sr.ReadToEnd();
sr.Close();

//Reading XML into a DataSet
DataSet ds = new DataSet();
sr = new StreamReader("MyFile.XML",Encoding.GetEncoding(1252));
ds.ReadXml(sr);
sr.Close();

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

Concatenated Fields
Frequently the need arises to concatenate two fields for displaying in the UI (perhaps in a ComboBox, DropDownList or in a Grid). You could handle this when you first get the data, by concatenating the two fields into a third field in your SELECT statement, but there is another way to do it with ADO.NET and that is to create a calculated column in your DataSet.
this.oData.Columns.Add("MyConcatField");
this.oData.Columns["MyConcatField"].Expression = "MyField1 + MyField2";

from a solution provided by Bonnie Berent in Message #1048819

Active Directory and ASP.NET
How difficult is to get who is currently logged into the ASP.NET page when using Active Directory?

The user's NT account is linked to Active Directory, so the web site would have to use impersonation to be aware of the user's NT/AD account. If this is the case, the NT account info is already attached to the HTTPApplication. You can get to the account name with the following code:
CType(Application.User.Identity, System.Security.Principal.WindowsIdentity).Name

From there, if you want to get the AD properties associated with that name, you can use:
System.DirectoryServices.DirectorySearcher

Be aware that AD is a freeform cache of name-value pairs. If the directory is not expertly maintained, it will be very difficult to get meaningful data 100% of the time.

from a solution provided by Keith Payne in Message #1038223

Edit Menu with Copy/Paste functionality
There are methods on textboxes for doing this (MyTextBox.Copy(), MyTextBox.Paste(), etc.). In the Click Eventhandler on your Menu, you need to drill down through your Container controls to the ActiveControl and if it's a text box, then run the appropriate method:
// The click eventhandler for the Copy menu item:
public void ClickHandler(object sender, System.EventArgs e)
{
    if (Form.ActiveForm != null)
    {
        Control o = Form.ActiveForm
        while (o is ContainerControl)
        {
            ContainerControl oContainer = (ContainerControl)o;
            o = oContainer.ActiveControl;
        }
        if (o != null && o is TextBox)
            ((TextBox)o).Copy();
    }
}

Do this for each of your menu Click Eventhandlers.

from a solution provided by Bonnie Berent in Message #696109

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, 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, May 1, 2007
Great 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