Customize default folder of Windows Explorer

If you have noticed when you click on the Windows Explorer icon default folder in task bar in Win 7, it would go to libraries folder. You can customize this behavior. Let’s say we need to set the default behavior to open My Computer.



Here are steps to change it from libraries to my computer:


1. Close all the windows explorer windows.

2. Press Shift key and right click on the explorer icon



3. Click Properties menu item and Click Properties menu item and Go to Shortcut tab.

4. Change the Target to : %SystemRoot%\explorer.exe /E,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}







5. Click Apply and Ok button.


So next time you open the windows explorer it would open my computer folder.

Windows 7 Tips

Minimize Everything except the current window

Many times we have a lot of applications open on the screen and if we have to minimize or hide other windows that are open in the background.
Then this tip can be handy.
Press the Windows Key + Home Key.
This would minimize all the background windows.

Box Selection and Multi-Line Editing with VS 2010

Technology:
Visual Studio 2010

Title:
Box Selection and Multi-Line Editing with VS 2010

Description:
Box selection is a feature that has been in Visual Studio for a while. It allows you to select a rectangular region of text within the code editor by holding down the Alt key while selecting the text region with the mouse.

With VS 2008 you could then copy or delete the selected text.

VS 2010 now enables several more capabilities with box selection including:
• Text Insertion: Typing with box selection now allows you to insert new text into every selected line

• Paste/Replace: You can now paste the contents of one box selection into another and have the content flow correctly

• Zero-Length Boxes: You can now make a vertical selection zero characters wide to create a multi-line insert point for new or copied text

These capabilities can be very useful in a variety of scenarios.

Some example scenarios: change access modifiers (private->public), adding comments to multiple lines, setting fields, grouping multiple statements together, restructuring HTML.

Running Batch Script from C#

Here is another example code to run batch script from C#


public void RunBatchScript(string batchPath, string arguments)
{
Process process = new Process();
process.StartInfo.FileName = batchPath;
process.StartInfo.Arguments = arguments;

process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;


process.OutputDataReceived += new DataReceivedEventHandler(writeStdOutStreamInfo);
process.ErrorDataReceived += new DataReceivedEventHandler(writeStdErrStreamInfo);

process.Start();

process.BeginErrorReadLine();
process.BeginOutputReadLine();

// Wait for the process to end
while (!process.HasExited)
{
Thread.Sleep(500); // sleep
}
Console.ReadKey();
}
public void writeStdOutStreamInfo(object sender,DataReceivedEventArgs e)
{
string s = e.Data;
Console.WriteLine(s);
}
public void writeStdErrStreamInfo(object sender, DataReceivedEventArgs e)
{
string s = e.Data;
Console.WriteLine(s);
}

Using there event handlers we will get the standardoutput and standarderror asynchronously in the command prompt

LinQ to XML

Using LinQ to XML its very easy to query the Xml files and traverse through the nodes and elements.
Here is one simple exaple to read the configuration XML file

bellow is my simple XML configuration file



CPADCE008
CPADCE008VM1
CPADCE044
CPADCE044VM4
20100504



Then here is the simple class to load the XML file

class ConfigElements
{
public string ServerMain { get; set; }
public string ServerVM { get; set; }
public string ClientMain { get; set; }
public string ClientVM { get; set; }
public string LatestBuild { get; set; }

public ConfigElements(XElement xElement)
{
ServerMain = xElement.Element("ServerMain").Value;
ServerVM = xElement.Element("ServerVM").Value;
ClientMain = xElement.Element("ClientMain").Value;
ClientVM = xElement.Element("ClientVM").Value;
LatestBuild = xElement.Element("LatestBuild").Value;
}

public ConfigElements(string ID)
{
XDocument doc = XDocument.Load("XMLFile2.xml");

var query = from xElem in doc.Descendants("Automation")
where xElem.Attribute("ID").Value ==ID
select new ConfigElements(xElem);

}
}


By creating the object of this class we will get all the reqired nodes

ConfigElements objConfigElements = new ConfigElements("1");
//pass here the Id of the requied values
string s= objConfigElements.ServerMain;
string t = objConfigElements.ServerVM;
string u = objConfigElements.ClientMain;
string v = objConfigElements.ClientVM;
string w = objConfigElements.LatestBuild;