Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Monday, April 27, 2009

Run System Process without showing Command Window and get an output

In this post I would like to show the sample code on how to start a process without showing a console window and get an output result. I am going to use System.Diagnostics.Process class and set parameters to it. Function below will execute a specified command with parameters and return an output on successful run or nothing if there was an error.

using using System.Diagnostics;
private static string RunProcess(string command, string parameters)
string output = string.Empty;

Process process = new Process();
process.StartInfo.CreateNoWindow = true; // Don't create command window
process.StartInfo.FileName = command;
process.StartInfo.Arguments = parameters;
process.StartInfo.UseShellExecute = false; // Don't use system shell for execution
process.StartInfo.RedirectStandardOutput = true; // Give us an output
process.StartInfo.RedirectStandardError = true; // Give us an error output
bool r = process.Start();

StreamReader streamReader = process.StandardOutput;
// Read the standard output of the spawned process.
output = streamReader.ReadLine();
if (output == null)
StreamReader errorStream = process.StandardError;
string error = errorStream.ReadToEnd();


return output;

This function can be modified to return an error output in exception or logged into file.


Thursday, April 16, 2009

Install/Uninstall and Manage Windows Service using Service Control (sc.exe)

Service Control program is a powerful tool that can be used to Install/Uninstall and perform other actions on Windows Services. Sample screenshot shows different parameters and options for sc.exe tool.


I will base my example on creating SVN version control Windows Service.

To install SVN Windows Service run

sc create "Subversion Server" binpath= "path_to_subversion\bin\svnserve.exe --service --root "C:\SVNRoot""

    displayname= "Subversion Dev Repository" depend= Tcpip start= auto

To Uninstall SVN Windows Service run

sc delete "Subversion Server"

Make sure that you put space after ‘=’.

Once SVN Windows Service is created allow svnserve.exe in Windows Firewall.


How to create a Windows service by using Sc.exe

Setting up a Subversion Server under Windows


Tuesday, April 7, 2009

How to clone DataRow and get its auto-incremented ID number after inserting into Access Database

In my work with Access Database I needed to duplicate an existing row in the table and get an ID of newly inserted row. Below are short snippets of code showing how.

Duplicating a DataRow

// load the data into Data Table
DataTable dataTable = tableAdapter.GetData();

// clone a Data Table
DataTable duplicatedDataTable = dataTable.Clone();

// get row to duplicate
DataRow row = dataTable.Rows[0];

// import row into cloned Data Table

This way we get a deep copy of the existing row and later use table adapter to insert it into database.

Getting auto-incremented ID number after inserting a row into Access Database

The actual idea of getting an auto-incremented ID of the new row in Access Database is very simple. Right after insert of the row we need to execute similar query to this one:


In order to avoid loading wrong ID in multi-user environment it is good to add some WHERE selection criteria which will limit selection only to duplicated rows. MAX function will pick the ID of the last inserted row.


Saturday, March 21, 2009

Integrating PartCover with Visual Studio 2008

One of essential tools in the software development is code coverage. Together with unit testing tools like NUnit it is easy to see how much of the code is covered by tests. Ideally Developer need to aim for 100% of code coverage when creating Unit Tests. This tutorial will use one of my software projects Windows Environment Variables Manager or EnvMan as an example.  On EnvMan website you can find another post that shows integration of PartCover with Visual Studio 2005. Technically there is no much difference between Visual Studio 2005 and 2008, this post covers version 2.2.0 of the PartCover and shows updated batch script as latest version of the PartCover required some changes to it.


As first step we need to download and install latest version of the PartCover. It is available from SourceForge site. Once installed we need to create PartCover.cmd batch file.

REM === Start PartCover.cmd ===
"C:\Path\To\PartCover\partcover.exe"--target "C:\Path\To\NUnit\nunit-console.exe"--target-work-dir %1 --target-args %2 --output %1\partcover.xml --include %3

"C:\Path\To\PartCover\PartCover.Browser.exe" %1\partcover.xml
REM === End PartCover.cmd ===

Integrating PartCover with Visual Studio 2008

To integrate PartCover with Visual Studio select menu Tools\External Tools ...

In the External Tools Dialog box click Add and enter the following data in the fields.


Part Cover




$(ProjectDir)\bin\Debug $(ProjectDir)\bin\Debug\$(TargetName)$(TargetExt) [*Assembly Regular Expression*]*

Initial Directory:


Tick Use output Window and Prompt for Arguments. Click OK

Running PartCover

To run PartCover select EnvManagerTest project and use Part Cover from Tools menu. Because we ticked "Prompt for Arguments" the following dialog box appears.

Replace "Assembly Regular Expression" with "EnvMan" so it looks like this [*EnvMan*]*. Please look at PartCover documentation for more details about regular expressions. After OK is clicked output window of Visual Studio will show a progress of the coverage test and Part Cover Code Browser window will appear. Unfortunately PartCover Code Browser does not open generated report file automatically. Use Open File menu to view generated partcover.xml report file.

Friday, March 20, 2009

Free Icon Collections

Recently I was looking for free icons I could use for my web and desktop application development and came across few sites. Below is a list of links and references that might be very useful.

Application Icons

Sweetie - Cute and clear icons

Sizcons - A nice and useful set of icons to customize your applications

ASP.NET Icons - 300 professionally designed icons for your ASP.NET applications

Animated GIFs

Activity indicators - Link1, Link2, Link3

Free Internet Icon Search Services

ICONLook - Search Icons on Internet

IconFinder - ICON Search made easy

IconLet - ICON Search

Icon Search Engine - Search ICONs on Internet


For these who likes to see more follow the links below.

Free 40 Icon Sets


20 Free and Fresh Icon Sets

Icons for your Desktop and Web Designs

Free Icon Web 35 Free Icon Sets

Icons Free

Icon Archive


Free Icons, Buttons and Templates

Icons Review Open Clipart

55 Free High Quality Icon Sets

Monday, February 23, 2009

Creating Service Reference: Failed to generate code for the service reference

I was working on Windows Service that was consuming another WCF Windows Service. I created a Service Reference in Visual Studio 2008 and noticed that client code was not automatically generating. The error I was getting was

Error 4 Custom tool error: Failed to generate code for the service reference 'MyWindowsService'. Please check other error and warning messages for details.

The Windows Service I was working on was already full blown project with lots of references, so to limit possibilities I created another empty windows service and added Service Reference to one I need. Client code was generated with no problems! I decided to use new Windows Service as a base and added all required functionality to it and selected “Update Service Reference” and again it failed to generate a code!


After some time looking around there was an easy solution to fix a problem. You need to edit Service Reference Configuration by selecting “Configure Service Reference…” from right click menu.


In the dialog box Un-tick “Reuse types in referenced assembles” and click OK. Try to Update Service Reference. This worked for me!


.NET C# Broken WCF service reference in VS 2008


Thursday, February 12, 2009

ASP.NET page validation and redirection to a new page

I was working on the ASP.NET web site where users register using form and get redirected to a different page on pressing submit button. Easy way to redirect to a new page is to use PostBackUr property of the button.

<asp:Button runat="server" ID="BtnSubmit"  Text="Submit" PostBackUr="newpage.aspx" />

Unfortunately this does not work if we need to handle button OnClick event. Solution is to use Server.Transfer or Response.Redirect of the Page control.

protected void BtnClick(object sender, EventArgs e)
if (Page.IsValid)
// Do something ...


Page.isValid is true if all validators on the page and in web controls returned valid. A very good explanation about the difference between Server.Transfer and Response.Redirect can be found in the link below.

Server.Transfer Vs. Response.Redirect


Thursday, February 5, 2009

Getting Started with AJAX development and AJAX Control Toolkit

Developers who use Visual Studio 2008 know that AJAX already built into ASP.NET for .Net 3.5 Framework. All they need is to get AJAX Control Toolkit.

AJAX Control Toolkit .Net 3.5

How Do I: Get Started with ASP.NET AJAX? is an excellent video that helps to get started.

AJAX for .NET 2.0

If you are developing pure .Net 2.0 ASP.NET website or still using Visual Studio 2005 you need to get AJAX 1.0 and  AJAX Control Toolkit for .Net 2.0.


ASP.NET 2.0 AJAX Templates for Visual Studio 2008

AJAX Control Toolkit for .NET Framework 2.0, ASP.NET AJAX 1.0

AJAX Tutorials and Documentation

AJAX Website has extensive number of Tutorials and Control Toolkit has a sample website that will be very helpful to make learning curve shorter.


ASP.NET AJAX Documentation

AJAX Control Toolkit Tutorials (C#)

ASP.NET Learning Centre

Deployment of AJAX enabled websites

Once development is finished and project need to be deployed to testing or production servers, install ASP.NET AJAX 1.0 on the server if you are deploying ASP.NET 2.0 website. ASP.NET 3.5 website will require only .NET 3.5 runtime installed on the server. There is no need to install AJAX toolkit as long as toolkit DLL is distributed in bin folder.