Sponsored Ad

Sunday, July 24, 2011

Publish and Deploy Code using Visual Studio

Visual studio provide very easy and good feature to publish ad deploy the code  and dlls. Follow the below steps to deploy and publish:

Step 1: Right click on project and select the publish option

Publish and Deploy Code using Visual Studio

Step 2: Select the Directory where you want to publish

There is 4 kind of location

  1. Disk Path
  2. File Share
  3. FTP Server
  4. Web site

Select as per your requirement.

Publish and Deploy Code using Visual Studio

Step 3: Select How user will install applcation

Publish and Deploy Code using Visual Studio

Step 4: Select option for application to check for updates.

Publish and Deploy Code using Visual Studio

Step 5: Click on Finish and publish the solution.

Publish and Deploy Code using Visual Studio

Search/Replace Text in Entire Solution by using Visual Studio Search

Visual studio provide different kind of search to find text in file(s) or selected File(s). The search available with VS are:

  1. Quick Find
  2. Quick Replace
  3. Find in files
  4. Replace in Files
  5. Find Symbols

You do any of the above search in visual studio.

To do the search in entire solution Go to Edit Menu –> Find and Replace –> Find in Files

Search/Replace Text in Entire Solution by using Visual Studio Search

Find in Files Search:

Search/Replace Text in Entire Solution by using Visual Studio Search 

Shortcut key to Find in Files : CTRL + SHIFT + F

How to Format Selected Source Code in Visual Studio Editor

Visual studio provide a very good functionality to format your source code automatically. If you code is not well formatted don't worry. just by a single click you can align all code. follow the below steps to do that.

Step 1: Go to Edit menu option

Step 2: Select Advanced and then select Format Document

Step 3: There is another option Format  Selection under Advanced , Please not that this is applicable for selected text only, so first select the option and then click on this option.

Shortcut keys for above functionality:

Format Document CTRL + E + D

Format  Selection CTRL + E + F

How to Format Selected Source Code in Visual Studio Editor

How to Change Font and Color of Visual Studio Editor

Visual studio provide a setting to change change font and color of text and other things available at editor. To change the look and feel follow the below steps:

Step 1: Click on Tools menu from visual studio IDE.

Step 2: Select Options from Tools menu.

Step 3: Select Environment and then select Fonts & Colors option

From the Fonts & Colors page you can change the font and color of different elements.

for example selected text, line number , book mark etc.

How to Change Font and Color of Visual Studio Editor

After changing the text color to red you can see that editor is showing normal text in red.

How to Change Font and Color of Visual Studio Editor

How to Edit Readonly File and Warn when Save in Visual Studio

Visual studio provide a option to allow editing of read only files. and if option is enable it will also display a message to override it. To enable disable read-only file option follow the below steps.

Step 1: Open Visual Studio – > Click On Tools menu

Step 2: Select Options

Step 3: Click on Environments  and then select Documents

Step 4: Under Documents page select/unselect “Allow editing of read-only files; warn when attempt to save” checkbox.

How to Edit Readonly File and Warn when Save in Visual Studio

Read only file save warning.

How to Edit Readonly File and Warn when Save in Visual Studio

Enable/Disable Visual Studio Notification When File is Changed from Outside

If a file which is already open in visual studio and is changed from outside of visual studio environment. The visual studio have a setting to tell you that file is changed and you want to reload this file or not.

if you click on yes it will reload the file otherwise will have old version of file.

Follow the below steps to enable/disable this setting.

Go to Tools –> Options –>  Environments –> Documents

and Enable disable Detect when file is changed outside the environment Checkbox.

Enable/Disable Visual Studio Notification When File is Changed from Outside

If you select the Auto-Load Changes if Saved , The visual studio will automatically reload the file.

Enable/Disable Visual Studio Notification When File is Changed from Outside

Saturday, July 23, 2011

Display/Show Toolbox in Visual Studio + Shortcut Key

To display Toolbox in Visual studio IDE, Follow the below steps:

Step 1. Go to View menu

Step 2: Click on Toolbox option,  the toolbox will appear in left hand side of visual studio.

Display/Show Toolbox in Visual Studio + Shortcut Key

There is keyboard shortcut  also to display toolbox

Press CTRL key + W + X from keyboard

How to Open/Display Solution Explorer in Visual Studio | Shortcut key

This post is to help, who are new to visual studio. If you closed the solution explorer from visual studio IDE. you can follow the following steps to display again:

Step 1: Go to View menu

Step 2: Click on Solution Explorer Option 

How to Open/Display Solution Explorer in Visual Studio | Shortcut key

Shortcut keys to open solution explorer:

Press  CTRL + W + S key to open solution explorer

Visual Studio Settings: How to Enable Word Wrap

The below steps will help you to enable word wrap in visual studio.

Step 1: Go Tools menu

Step 2: Click on Options

Step 3: Select The Text Editor and then select your language or All Language for All

Step 4: Select General and then go to settings option

Step 5: Select the Word Wrap option and click on save.

Tools –> Options –> Text Editor –> C# or All Language –> General –> Settings –> Check Word Wrap Option

How to Enable Word Wrap in Visual Studio Editor

Note : there is a option to show visual glips for word wrap, if you enable this you will get the visual indicator like below:

How to Enable Word Wrap in Visual Studio Editor

.NET Tips: Show Line number in Visual Studio Editor 2005/2008/2010

You can display line numbers in your visual studio editor. Just follow the following steps to display line numbers. by default line number are hidden.

Step 1: Go to Tools menu at the top of VS.

Step 2: Go to Options

Step 3: Go to Text Editor and then select C# or your language.

Step 4: Select Line number under display options.

Click on OK and it will display he line number in editor.

C# Tips: Display Line number in Visual Studio Editor 2008

Displaying line numbers in editor:

C# Tips: Display Line number in Visual Studio Editor 2008

Find Current Executing Assembly Name using C# Program

You can find out current executing assembly name by using the reflection. Reflection provide lot more details about the current executing assembly and you can read at runtime. The fully executing code is given below.

The below code is using GetExecutingAssembly() method to get the detail of current assembly.

Find Current Executing Assembly Name using C# Program

C# Example to Display Current Assembly Name:

using System;
using System.Data;

namespace DemoConsoleApplication

    class Get_Current_Assembly
    {
        static void Main(string[] args)
        {
            string str_Assembly_Name;
            str_Assembly_Name = System.Reflection.Assembly.GetExecutingAssembly().FullName;
            Console.WriteLine("Full Assembly Name: " + str_Assembly_Name);

            str_Assembly_Name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            Console.WriteLine("Only Assembly Name: " + str_Assembly_Name);

            Console.ReadLine();
        }
    }
}

Sample Program to Dispose Dataset by Using Block in C#

If you want to dispose dataset object after a certain operations. You can initialize dataset object inside the using block and the dataset object will automatically dispose once the block finish. Even the dataset object will not be available after the using block.

You can run the below code and check the this is one the good way to avoid the headache of disposing dataset.

Sample Program to Dispose Dataset by Using Block in C#

C# Example to create dataset object in using block:

using System;
using System.Data;

namespace DemoConsoleApplication
{
    class DataSet_Using_Block
    {
        static void Main(string[] args)
        {
            //Create a object of dataset in using block
            using (DataSet oDs = new DataSet("DemoDataset"))
            {
                Console.WriteLine("DataSet Created.");
                Console.WriteLine("DataSet Name inside using block:" + oDs.DataSetName);
            }

            try
            {
                //The below code will not compile as oDs is not visible.
               // Console.WriteLine("DataSet Name outside of using block:" + oDs.DataSetName);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error Message: " + ex.Message );
            }

            Console.ReadLine();
        }
    }
}

What Dataset Namespace should be Included in C#

You can create a dataset object by including the System.Data namespace as dataset class is inside this namespace only.

The below program will help you to include the dataset namespace and also create a dataset object by specifying the name of dataset.

What Dataset Namespace should be used in C#

Sample program to create a dataset object and include the namespace:

using System;
using System.Data;

namespace DemoConsoleApplication
{
    class DataSet_NameSpace
    {
        static void Main(string[] args)
        {
            //Create a object of dataset
            DataSet oDs = new DataSet("TestDataset");
            Console.WriteLine("DataSet Created.");
            Console.WriteLine("DataSet Name:" + oDs.DataSetName);
            Console.ReadLine();
        }
    }
}

Sponsored Ad

Development Updates