" Live as if you were to die tomorrow. Learn as if you were to live forever.. "
- Mahatma Gandhi

Run the existing SQL Script programmatically with SMO

Posted on November 24th, 2015 by Shibani Shubhadarshini

SMO ======== SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server.   We can integrate SMO into any .NET based applications. SMO is also compatible with SQL Server version 7.0, SQL Server 2000, and SQL Server 2005, which makes it easy to manage a multi-version environment. Following code is […]

Checking resource leaks in a form

Posted on November 24th, 2015 by Naibedya Kar

In a .net windows application the form might have resource leaks though it is running with managed codes. We can use the below procedure to check if a form is having resource leak. Open  Windows Task Manager Click on Process tab. Select “View” in the menu and then select “Select Columns” menu item. Check the […]

Code optimization through WeekReference

Posted on November 24th, 2015 by

WeekReference is a new element added into 4.5 framework, but it was available in Java from the earlier stage only. So, this article could be useful for .Net, Java, and Android as well. What is it? It is nothing more than a class but what special about is to interact with Garbage Collector in a certain way […]

3 Tips for boosting your .net Business/Server Products

Posted on November 23rd, 2015 by Amit Ranjan

1. Write windows Event Log Use Windows Event log to ensure that your app is working as expected. Useful in notifying the System Administrator, in case some failures or important events occur? Sample Code: using System.Diagnostics; public void WriteEventLog(string strCallerName, string strLogLine) { if (!System.Diagnostics.EventLog.SourceExists(strCallerName)) { System.Diagnostics.EventLog.CreateEventSource(strCallerName, “Application”); } EventLog EventLog1 = new EventLog(); EventLog1.Source […]

Running setup created in VS 2003 in higher versions of .NET Framework

Posted on November 23rd, 2015 by Amrita Dash

When we try to install \ run a setup MSI file created using Visual Studio 2003 , in a machine having higher version of .net framework , it will not allow to install the product and throws an exception as follows. “This setup requires the .NET framework 1.1.4322.Please install the .NET Framework and run this […]

How to restart a Windows Service programmatically ?

Posted on November 23rd, 2015 by Richi Padhi

To restart a Windows Service we can use the ‘Recovery’ properties as provided by the SCM itself. Just follow the instructions : From Start Menu go to –> Control Panel –> Administrative Tools –> Services –> (Select your Service) Then right click on your service and go to its properties, there you can find the […]

Document merging in C#.NET

Posted on November 23rd, 2015 by Shantilaxmi Patro

Some times during application development we need to generate a MS Word document from a predefined format and some custom data. The predefined format is generally called as Template. This template used to carry some merge fields which can be replaced with the user data. The user data can be taken from DB or XML […]

Using NULL-COALESCE Operator in C#

Posted on November 23rd, 2015 by Rabinarayan Biswal

To my knowledge perhaps the least used operator in C# is the null-coalescing operator . But you can use it effectively to reduce the lines of code you write . The null-coalesce operator can be used to define / return a default value for a nullable value type / reference type and this is represented […]

Create Dynamic Objects at runtime using Reflection

Posted on November 23rd, 2015 by Satyadeep Kumar

Sometimes there is a need to create duplicateinstances of a same class ( objects with same values for the properties, and fields. ) When the class is of known type,  it’s easy to duplicate the instances. For e.g.: Consider a class called MyClassExample Class MyClassExample { public int NUMBER1 {get; set;} public int NUMBER2{get; set;} […]

How to avoid creation of duplicate names for objects in Object Repositories having the same properties

Posted on November 23rd, 2015 by Vivek Mishra

Sometimes you will see duplicate browser/page objects are created while recording against a Web application in spite of having all the properties same inside Object repository. For ex: You may find PageName_1, Browser_1 added inside Object repository when you are recording against same application. To get rid of this problem perform the following steps: Go […]

How to install .NET Framework assemblies in SQLServer 2005 for CLR integration

Posted on November 23rd, 2015 by Rupesh Nayak

Some times we need to refer the .NET Framework assemblies and namespaces that are not by default available for development of CLR database in SQLServer. In such scenarios we can register the assemblies in to the SQLServer and then can access them in our CLR objects. The System.Management  namespace/assembly which is not available in SQLServer […]

Using constraints in Dataset

Posted on November 23rd, 2015 by Naibedya Kar

As we all know Dataset plays a significant role while working with .net applications. Those who are new to dataset, it is just an in memory representation of table data. This object is sufficient to differentiate classic ADO and ADO.NET. Constraints are nothing but conditions applied to the table Column or Columns to maintain data […]

Dispose pattern for .Net Applications

Posted on November 23rd, 2015 by Priyanka Dash,

Dispose pattern is nothing new but a better approach of disposing managed as well as unmanaged objects. This has been referred by the MSDN and meant for a better architecture towards object disposal in .Net applications.   The backbone of .Net applications, the CLR, does not have any control over the unmanaged resources. It can’t […]

How to close a Connection object automatically when we close the associated Reader object

Posted on November 23rd, 2015 by Amit Mohapatra

In some situations we feel the need to close a SQL connection object immediately after the SQL query operation with a associated reader is complete. We can not close the connection before we complete all the operations related to the reader. Also we need to close the connection immediately after we finish the use of reader object. […]

FindExecutable API

Posted on November 23rd, 2015 by Amrita Dash

With the help of FindExecutable  Windows API we can trace whether a particular exe is present in the system. It will return a result depending on the handle of the executable associated with the file provided as parameter. It returns a value greater than 32 when successfull.   Lets say for example , we pass a […]

A brief idea about Cookie ASP.NET

Posted on November 23rd, 2015 by Santosh Bisoyi

What is a Cookie ?   A Cookie is an object is used to store the sort amount of data onto client end. It executes on server and resides on client browser.   How does Cookie work ?   when users request a page from your site, your application sends not just a page, but […]

DataTable Compute Method

Posted on November 23rd, 2015 by Priyanka Dash

Compute is one of the methods of DataTable class. This method computes an expression on the current rows that pass the filter criteria.   Syntax Object DataTable.Compute(string expression , string filter)   Expression – The expression to compute. Filter – The filter to limit the rows that evaluate in the expression.   This method’s return […]

Tips,Tricks and Traps on Adding Web Reference using Visual Studio 2005 and Visual Studio 2008

Posted on November 23rd, 2015 by Himanshu Sahu

Issue: Severity – Very High      In one of our windows service, we have been using a web reference for last two years. Just to do some upgrade work, we got the code of this windows service in another machine. Due to some reason we missed that web reference and needed to add again that […]

Nullable Type in .NET

Posted on November 23rd, 2015 by Shantilaxmi Patro

The nullable type can represent a normal or regular set of values for its value type including the null value.     If we take an example of bool type, then Nullable<bool> can contain set of values like true or false or null.So, assigning null value to bool is useful when we are dealing with database […]

What is the use of bindingRedirect in the config file ?

Posted on November 23rd, 2015 by Premananda Das

Suppose we made an application and the dll is present in the GAC. Now if we make another version of the same  dll and put the dll in the GAC,which dll should the application refer ?    Ans.The application will refer to the latest version of the dll. But what do we have to do if we […]

Add a pinch of salt to data access performance

Posted on November 23rd, 2015 by Rabinarayan Biswal

 To acess data from a Data Reader, we mostly use the column / field name to retrieve data from a field .   And we use field name instead of index atlest for the following two reasons :- 1. using field name instead of index makes the code more readable 2. if the column order changes […]

Fill a PDF form using iText in .NET

Posted on November 23rd, 2015 by Monalisa Brahma

To Fill a PDF form you need Adobe Acrobat Professional Version in your Machine. Here are the following steps to achieve the above   1st Step:Open the PDF to be filled with Adobe Acrobat Professional version 2nd Step:Go to Form Menu -> Form Tools->Add the respective controls to your PDF form and assign its name […]

Check to see if file has exclusive access to open and read

Posted on November 23rd, 2015 by Amrita Dash

Following is a sample method to check if a file has exclusive access to open and read.If the file is being used by other process the function will return true.   [VB.NET CODE STARTS]   ‘– Add reference to System.IO   Imports System.IO   ‘—————————————————————    Private Function IsFileInUse(ByVal filePath As String) As Boolean Dim […]

Iterate thorugh collection for unique values only (using LINQ and C#)

Posted on November 23rd, 2015 by Satyadeep Kumar

Sometimes we work with collections that contain duplicate data and we just want to iterate over unique values inside the collection. To iterate only through unique values, we generally have to use for-loop and check (compare) each and every data inside the collection for duplicate entries, which is a bit tedious task. However, if you are using Linq it becomes […]

Implementing Auto Number Column in DataTable in .Net:

Posted on November 23rd, 2015 by Rashmita Devi

DataTable class of .Net provides a good option to add Auto Number Column which we generally use for showing the Serial No. in the GridView, so we instead of getting that from DB we can use the DataTable .   You can add this type of column by setting some properties of that column. For example: […]

Getting the Calculated value for a new column of a DataTable in .NET

Posted on November 23rd, 2015 by Rashmita Devi

DataTable class in .Net supports the calculation of a column by getting the values from other columns. That means lets say I have a DataTable as dtItems which is having three columns ItemName, Price, Quantity ,if I need to add another column asTotal and the calculated value for this column will be Price* Quantity , […]

Gearing up performance in ADO.NET

Posted on November 23rd, 2015 by Rabinarayan Biswal

While working in a project around a year back, I was facing trouble while downloading data from a SQL server to sqlite database. The SQL server DB contained  millions of records (CAd/CAM refernece data) in some table that I needed to download to the SQLite DB.In fact the records were inserted to the SQL server […]

Using MARS technique in C#.NET 2.0

Posted on November 23rd, 2015 by Rasmita Mohanty

MARS (Multiple Active Result Set) is a new concept in Visual Studio 2005. MARS means we can work with the same reader without closing the opened reader. This means opening and closing the connection for each time use of a DataReader is no longer a requisite   Suppose we take a SqlDataReader object in our […]

How to register the .NET assembly for COM interop if Visual Studio .NET or any other .Net framework is not installed

Posted on November 23rd, 2015 by Pallavi Kar

Visual Studio .NET in general generates both .dll and .tlb files when the solution is built for creating an assembly. But if we are using Express edition, the .tlb file is not generated automatically, we need to explicitly create it. This tip shows how to achieve the above objective by following the steps given below: […]

How to create custom attributes in .Net

Posted on November 23rd, 2015 by Priyanka Dash

Attribute: “An attribute is a piece of additional declarative information that is specified for a declaration.“  Attributes are needed to write codes in a better style, in a better way. Its may not be mandatory to use attributes in your coding but it should be used for a better architecture. It can be used to […]

Measure execution time of a block of code in .NET

Posted on November 23rd, 2015 by Aditya Acharya

When we jump into performance of our application. Its essential to track which of the code segment is taking more time. To track the time taken by your code or your query you can use System.Diagnostics.Stopwatch instance before execution started of the specific code. And after completion of the code execution calculate the time elapsed. […]

Populating datagrid from a XML file in.NET

Posted on November 23rd, 2015 by Monalisa Chakraborty

This tip explains how you can populate a datagrid with values of specific nodes of a XML file. The XML file we are taking in this example contains month names. We have to retrieve month names corressponding to particular nodes. The month node itself is further divided into 3 parts. The first part contains the […]

How to save values from data grid to an XML file?

Posted on November 23rd, 2015 by Monalisa Chakraborty

In this tip we will see how to save datagrid values to an XML file. The data is to be stored in 3 nodes – data name, value and comment . The following code snippet demonstrates how to save datagrid values to an XML file.     Dim objDoc As New XmlDocument() ‘object for access […]

Is it necessary to call Dispose() on a Dataset?

Posted on November 23rd, 2015 by Nirmal Hota

Dataset is a disconnected managed object.   Dispose() is typically called to release unmanaged resources such as file-pointers, streams etc. In most cases, such classes also expose a Close()method that is more appropriate for them.   Dataset class is being inherited from the MarshalByValueComponent. This implements the IDisposable interface as it is a component. The […]

How to keep the scrollbar down in Windows Form MultiLine TextBox

Posted on November 23rd, 2015 by Tushar Mishra

In a MultiLine textbox when a large amount of text is put into, a scrollbar appears if the scrollbar property has been set to vertical. But by default the scrollbar maintains its position at top no matter how long the text content is. If you want to programmatically keep the scrollbar down to the last […]

Dealing with Collection Containing objects (reference types) in .NET

Posted on November 23rd, 2015 by Satyadeep Kumar

We speak about Reference Types, Values Types very often and it’s common knowledge that Value Types are stored on stack and Reference Types are stored on heap. Value type contains values, and Reference Type contains address pointed to that memory location. Have you ever thought what can be the impact while dealing with the collection […]

Solution for attaching process while multiple worker Processes (w3wp.exe) are running

Posted on November 23rd, 2015 by Monalisa Pradhan

At the time of debugging ASP.NET web application, we are attaching the particular worker process (tools -> Attach process) .   The process window will show the worker process (w3wp.exe) which is currently running on IIS. We select the process and click on attach button to start the debugging. But the problem here is that […]

Registering a COM Interop dll in .NET

Posted on November 23rd, 2015 by Amrita Dash

To create and register a COM interop dll with C#.NET (VS 2008) , we need to implement the following steps. 1. Create a class library project 2. Add a reference to Runtime.InteropServices in the class using System.Runtime.InteropServices; 3. Add Comvisible attribute to the class.  [ComVisible(true)]     public class clsHelloWorld {      // this class should […]

How to change the default template of class file in C#

Posted on November 23rd, 2015 by Nirmal Hota

Step 1 : Copy the zip file from C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip and paste this some where in the harddrive. Path may vary from machine to machine depending upon the .net  version and installation path.   Step 2:  Unzip the class.zip. You can find a Class.CS file inside the folder. This is the default template file […]

How to skip certain breakpoints during debugging

Posted on November 23rd, 2015 by Monalisa Pradhan

Sometimes we don’t want to go stepping inside methods while debugging though certain break points. Suppose we have more than one method in a page. While debugging we don’t want to step into a particular method, in other words, we want to skip that method. So what do we do ? We can use the “DebuggerHidden” […]

How to avoid build error after changing name or declaration of a method

Posted on November 23rd, 2015 by Monalisa Pradhan

While working in a big application where more than one developers are involved, sometimes we may need to change the name or declaration of a particular method – which in turn gives build error or causes the application to crash as it is being used by other  developers in the application. In this situation we […]

Passing Anonymous Type in Function calls using dynamic (C# 4.0)

Posted on November 23rd, 2015 by Satyadeep Kumar

Anonymous Types were introduced in C# 3.0 (.Net Fw 3.0)   Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type. Dealing with anonymous type within a function was easy and a great aid while programming but when it came to passing […]

How to Compare Numeric Value with String in LINQ to Entity Query

Posted on November 23rd, 2015 by TUSHAR MISHRA

In Linq to Entity Query, When one data type is Integer and other is of type string then to avoid type mismatch problem, one cannot use Convert.ToInt32() Function with string parameter or .ToString() function with the integer parameter. It will give you the following error :   “LINQ to Entities does not recognize the method ‘System.String […]

ClientIDMode on Asp.Net 4.0

Posted on November 23rd, 2015 by Srikanta Barik

Accessing the control’s id at runtime, when the page being used is the master page, has been a persistent issue, especially when we are trying to access the control’s id(Client Id) using Javascript. When we are adding the content to our aspx page, it resembles : <asp:Content ID=”Content1″ ContentPlaceHolderID=”MindfireContent” Runat=”Server”> <asp:Textbox ID=”txtMindfire” runat=”server” Text=”Proud to be Mindfireans” /> […]

Effective ways to add items dynamically to list controls in WinForm

Posted on November 23rd, 2015 by Madhusmita Rout

Sometimes while developing a winform application, we may have to add the items to the list control (ComboBox, ListView, ListBox, TreeView) dynamically. Generally we do this by using Items.Add() method. But there is performance issue related to this. Whenever we add an item to the control, the control immediately repaints itself to reflect the changes. […]

.NET Tip “IComparable.CompareTo()” Vs “IComparer.Compare()”

Posted on November 23rd, 2015 by Madhusmita Rout

 The two interfaces, IComparable and IComparer  sound a bit confusing. They both are doing the same thing to some extent,  compare the objects in a collection and sorts the elements in a  list. So I was confused, when to use IComparable and  when to use Icomparer?  After some amount of google, I found out that […]

Performing cross thread operations using SyncronizationContext

Posted on November 23rd, 2015 by Bibhudutta Pradhan

Many of us may be familiar with the restriction against modifying a Control from any thread other than the one in which it was created, if we do so we get a CrossThreadOpeartionException. Instead, an event generated on another thread must be marshaled to the Control’s thread using its (or the Form that it belongs […]

Make your windows service desktop interactive

Posted on November 23rd, 2015 by HARSH WARDHAN

Microsoft Windows services enable you to create long-running executable applications that run in their own Windows sessions. Windows services basically do not have any user interface. So you cannot directly pop up any message or launch any form through your windows service. However, if at all there is any need for the UI like notify […]

Performance Issue with SetPixel() or GetPixel() Method

Posted on November 23rd, 2015 by Ratan Sharma

Use of the methods SetPixel() and GetPixel() in .Net Framework to access each pixel and modify them makes the processing a lot slower. Why?? ======     Basically as we know .Net is a managed code system which uses managed data.And when we are manupulating images which means we are dealing with these two methods :     1. GetPixel() : […]

Creating a SSH connection using ‘plink’ (PuTTY) via C# application

Posted on November 23rd, 2015 by Richi Padhi

What is ‘plink‘? Its a command-line SSH connection method provided by PuTTY. Lets say, you have an application running on windows platform and this application needs to connect to a DB residing on some other platform like Linux, via SSH connection. And you don’t want to manually go and establish the PuTTY connection for each […]

Check The Duplicate Files Inside A Folder

Posted on November 23rd, 2015 by Srikant Biswal

In our projects, some times we need to compare files and delete or move the duplicate files to another folder.LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. LINQ will help to check the duplicates files and return the list of duplicate […]

Using VB 6.0 DLL In .NET Framework:

Posted on November 23rd, 2015 by Pallavi Praharaj

To Create and register the COM object in VB6.0 1.File -> New Project -> ActiveX DLL -> OK 2.Change project name to ComProject. 3.Add class named it as COMClass 4.then in Code Editor Add a Function: Public Function AddingTwoNumbers(num1 As Integer, num2 As Integer) As IntegerAddingTwoNumbers = num1 + num2End Function 5.Save the Project. 6.File […]

Some common mistakes made by .NET developers

Posted on November 23rd, 2015 by Vijay Goyal

Some basic misapprehensions or faults which we come accross in .NET programming and their replacements.   # The most common error is swallowing exceptions: try { //Something } catch { //Do nothing. } # Don’t use “magic numbers” in your code.: Ex: if(mode ==3){…} elseif(mode ==4){…} Use Enumerations wherever possible, so the meaning, not the […]

Using FileSystemWatcher class in VB.Net

Posted on November 23rd, 2015 by Shibani Shubhadarshini

FileSystemWatcher is a class, that is part of the System.IO namespace in .NET. FileSystemWatcher class allows user to monitor changes such as the creation, editing, renaming, or deletion of files within a given subdirectory. Following example is given to call refreshSection method of ConfigurationManager to refresh AppSettings section of config file. Following code is used […]

To create a list of fonts (combo box with all the font names installed in the system) we can use InstalledFontCollection which represents the fonts installed on the system.

Posted on November 23rd, 2015 by Amrita Dash

To create a list of fonts (combo box with all the font names installed in the system) we can use InstalledFontCollection which represents the fonts installed on the system. [VB.NET CODE STARTS] ‘ Need to have System.Drawing reference Imports System Imports System.Drawing.Text Imports System.Drawing ‘ Create a obejct of InstalledFontCollection Dim InstalledFonts As New InstalledFontCollection […]

Working with mail merge word document using VB.NET

Posted on November 23rd, 2015 by Amrita Dash

This tip demonstrates how to attach the DB source and populate fields from table to a mail merged word document in VB.NET. Code Snippet Dim objWord As New Object objWord = CreateObject(“Word.Application”) ‘ Creating a word application Dim objDoc As New Object objDoc = CreateObject(“Word.Document”) ‘ Creating a word document object objWord.application.WindowState = 0 ‘ […]

Few Tips on C#/.Net

Posted on November 23rd, 2015 by Satyadeep Kumar

Few useful tips for C#/.NET 1. Nullable Types/Nullable Modifier(?):  We cannot directly assign “null” value to “Value-Type”. For this purpose nullable types has been introduced in C# 2.0.  using this we can assign null to “Value-Type” variables. For ex:     int? num = null; A nullable type has two members: HasValue: It is set to true when […]

Oops… Who Killed My OOPs?

Posted on November 23rd, 2015 by Sathyan R

Background: It is very common for people to use   <asp:SqlDataSource> to bind controls in ASP.NET web pages. There are many developers who use <asp:SqlDataSource>to bind controls in their aspx pages. It is also prevalent to bind <asp:DropDownList> also using this <asp:SqlDataSource> But is it OK to use this for every single control (let us say […]

An easy way to bind ‘DELETE confirmation message’ to .NET controls

Posted on November 23rd, 2015 by Santosh Bisoyi

You always come accross a confirmation message “Are you sure you want to delete this item ? ” while deleting an item. In web application basically  we attach a javascript function with the OnClientClick event of the server control to ask user confirmation before delete the item. So this is not a big problem if […]

Manage opening instances of .Net windows application

Posted on November 23rd, 2015 by Shibani Shubhadarshini

While creating a windows application in visual Studio 2005 the application set up supports user launch multiple instances of the application on a PC simultaneously. To avoid user launch multiple instances of the application, select the Make single instance application check box to prevent users from running multiple instances of your application. The default setting […]

Capitalizing first letter of each word in a string in C# according to culture.

Posted on November 23rd, 2015 by Shashi Ranjan

Very Often we come across the need to capitalize the first letters of some word or some text. For example : when we want to display users name or city name etc. Recently I came across the same problem . Since string class does not have a method to do this we could think that […]

Closing external windows from your .NET application programmatically

Posted on November 23rd, 2015 by HARSH WARDHAN

Where it can help: Suppose you want to close a window without closing that particular application and you only know the caption of the window. You cannot use process methods as it will close the entire application along with the window. Use the close_window() method along with window caption. Code: Imports System.Runtime.InteropServices <DllImport(“user32.dll”, SetLastError:=True, CharSet:=CharSet.Auto)> […]

Create and Update Views Programmatically in SharePoint

Posted on November 23rd, 2015 by Kaushik Mohanty

In SharePoint, View is a virtual representation of a set of data from a specific list. We can programmatically create and update views for a list. Provided below is an example in C#.Net which explains the approach of creating and updating views. The code is divided in to 2 parts i.e. Part I – describes […]