Microsoft Visual Studio .NET 2005 Tips

1. Reading app.config

The collection accessed as ConfigurationSettings.AppSettings["dbconnstr"]; has been deprecated.

1.1 Add a reference to System.configuration,
1.2 Add settings to App.config


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="dbconnstr" value="Password=pwd;Persist Security Info=True;User ID=uid;Initial Catalog=db;Data Source=server"/>
  </appSettings>
</configuration>

1.3 Use the following code to initialise the app.config file and access the data in any method in a console application:


static void myfunc()
{
    String sz = System.Configuration.ConfigurationManager.AppSettings["dbconnstr"];
}
static void Main(string[] args)
{
    // open configuration for reading
    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    myfunc();
}

ConfigurationManager.AppSettings can also be accessed by any web application.


2. Dumping form data

This can assist debugging during postbacks and page transfers.


protected void DisplayFormData()
{
    foreach (String s in Request.Form)
    {
        Response.Write(s + ": " + Request.Form.GetValues(s).GetValue(0).ToString() + "
\r\n"); } } protected void MyFunc(object sender, EventArgs e) { // blah... DisplayFormData(); }


3. Safe-String handling functions

For security reasons the C++ Compiler does not allow use of strcpy and other methods which are not length limited by default. This reduces the risk of buffer overrun errors. This warning can be removed by using the preprocessor directive _CRT_SECURE_NO_WARNINGS

It is highly recommended to move to the new StrSafe functions.
Article: MSDN Library


4. Remove ASP .NET Temporary Files Regularly

%WINDIR%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

5. Using the Hex Editor

Visual Studio 2003, 2005 and 2008 do not have the Open As... feature on the File\Open dialog as in Visual Studio 6.
Rename the file to .bin and then drag and drop it into the editor to be able to edit the data.

Back to index.