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

Backup SQL Database Through Code In VB.NET

Posted on November 24th, 2015 by Amrita Dash

Using the SQL SMO object we can easily take backup of SQL database through code. Following is the sample code used take backup.     [VB.NET CODE STARTS] ‘–Reference added Imports Microsoft.SqlServer.Management.Smo Imports Microsoft.SqlServer.Management.Common   ‘–Declare the backup object Dim WithEvents oBackup As New Backup   ‘–Method to take backup Private Sub BackupSqlDatabase()   Dim […]

Isolated storage in Silverlight application

Posted on November 24th, 2015 by Soumya Patnaik

We can use Isolated Storage as a virtual file system to store data in a hidden folder on our machine in silverlight application. Silverlight application is allocated the storage of 1 MB per application but we can increase the amount of storage. This is the function to get the data in the isolated storage   […]

Retrieving List of DB created by user from SQL Express 2005

Posted on November 24th, 2015 by Shibani Shubhadarshini

To populate the databases in SQL Express 2005 we use SQL Server Management object(SMO). This process retrieves all databases created by user along with the system databases. For getting the list of databases created by users only we have to use IsSystemObject property of databases. If the property is False then these are the databases […]

Populate records programmatically on Transaction screen of RMS POS front

Posted on November 23rd, 2015 by Shibani Shubhadarshini

This tip is to handle the scenario where the user needs to extract the transaction details from some text file or other source and show them on POS Transaction screen programmatically from RMS custom POS Add-Ins. Suppose the user has retrieved all the required values to be populated on transaction screen then by using the […]

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 […]

Determining the path of installer in .NET programmatically.

Posted on November 23rd, 2015 by HARSH WARDHAN

At times you may need to determine the path of the installer while installing your application. For example, you need to run a script or another executable through your installer. Now to find the path of the script(which you need to run through installer), you need to determine the path of your application’s installer. To do […]

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 […]

Extracting records from an Excel file to Datatable

Posted on November 23rd, 2015 by Shibani Shubhadarshini

When you try to extract the contents of an excel sheet to a datatable through .Net code you may find some datatable columns having no or some values in it. The datatable is not having all the values as it is there in the excel sheet it is extracting from. The actual reason behind it […]

Opening a word document in multiple versions of Word(.NET Windows Application)

Posted on November 23rd, 2015 by Shibani Subhadarshini

The following tip can be used to avoid any problem in opening a word document in multiple versions of MS Word in different systems. If we have a reference to Microsoft Word 8.0 Object Library and wrote the following code in VB.Net to open a word document. Dim oWord As Word.ApplicationClass oWard = CreateObject(“Word.Application”) oWord.Visible […]

Adding a folder browser control to Set up project

Posted on November 23rd, 2015 by Amrita Dash

Lets say you have a form designed that is being run by the installer class.In the form there is a browse button to open the FOLDER BROWSE dialog. If you just drag and drop a folderbrowser control and implement code to open the dialog using SHOWDIALOG method, a dialog will open up with no treeview […]

.Net – Produce Special effects when loading or closing windows

Posted on November 23rd, 2015 by Pradip Shukla

The AnimateWindow API enables users to produce special effects like rolling, sliding, fading when loading or closing windows. Parameters hwnd Handle to the window to animate. dwTime Specifies how long it takes to play the animation, in milliseconds. dwFlags Animation type. 1- Animate the window from left to right 2 -Animate the window from right […]

Adding an e-mail to Microsoft Outlook outbox using VB.Net

Posted on November 23rd, 2015 by Tapaswini Mohanty

This example shows how to add e-mail to Microsoft Outlook outbox using VB.Net For this tip to work, the MS Outlook must be installed on the machine. And another  important point here to get this code working is to add a reference to Microsoft Outlook Object Library x.o ,where x is the version of MS […]

Check if SQL express is installed on target machine

Posted on November 23rd, 2015 by Amrita Dash

We can check whether SQL express is installed on a machine or not and then can install it along with our application.Following is the code sample in VB.NET to implement the same. [VB.NET CODE STARTS HERE] ‘ Need to add System.Management reference Imports System.Management ‘ Check if SQL express is already installed in the destination […]

How to Generate a Report Header at Runtime when Printing/Exporting a Control using DevExpress XtraPrinting Library in VB.NET

Posted on November 23rd, 2015 by Tapaswini Mohanty

Using XtraPrinting library, we can achieve the following at runtime while Printing/Exporting a Control: add additional information to the report; add a report header; specify a page header or footer; specify the paper size, margins, orientation, etc. For this we have to import two namespaces: Imports System.Drawing Imports DevExpress.XtraPrinting The code below demonstrates how to  […]

DateTime Picker Cell in DataGridView

Posted on November 23rd, 2015 by Om Pathak

In a DataGridView if we have to create a DateTimePickerCell, then we have to host that control in GridView as there are no inbuilt cells like ComboBoxCell or LinkCell in this control Public Class CalendarColumn Inherits DataGridViewColumn Public Sub New() MyBase.New(New CalendarCell()) End Sub Public Overrides Property CellTemplate() As DataGridViewCell Get Return MyBase.CellTemplate End Get […]

Open MS WORD or MS EXCEL document and set focus in Vista

Posted on November 23rd, 2015 by Amrita Dash

In VISTA when you try to open a word document or excel sheet from your program [VB.NET code], it  always gets minimized to the taskbar.To resolve this issue you can use the following command of AppActivate. [VB.NET] ‘ CREATE AN OBJECT FOR WORD Dim objWord As Object objWord = CreateObject(“Word.Application”) objWord.visible = True ‘ OPEN […]

Importing data from a CSV file into a column with multiple commas

Posted on November 23rd, 2015 by Soumitra Das

If you have a CSV file from which you want to import the data into the database and the CSV file has a column which contains values separated by multiple commas, you cannot extract the data by using the Split() function. That is because of the fact that the number of values you get will […]

Showing messagebox as the topmost dialog

Posted on November 23rd, 2015 by Amrita Dash

During installtion of a windows application, if we have to show a custom message box, then the custom message box always comes behind the installtaion wizard form. To handle this issue one can create a form with topmost property set to true and open the message box having this form as owner. Following is 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 ‘ […]

How to Print Receipt by POS Printer using VB.Net.

Posted on November 23rd, 2015 by Girish Suman

In RMS some times we need to print receipt like Sales Receipt, Gift Receipt etc by POS printer. Before printing the receipt we need to make a string with using  escape sequences, that escape sequences recognized by the printer. If an escape sequence specifies an operation that is not supported by the printer station, it […]

Open password protected Word document

Posted on November 23rd, 2015 by Amrita Dash

The following code sample shows how to open a password protected word document using VB.NET [VB.NET CODE STARTS] Dim objWord As Object Dim strPassword as string = “YOUR PASSWORD” objWord = CreateObject(“Word.Application”) objWord.visible = False objWord.application.WindowState = 2 objWord.application.DisplayAlerts = False Try objWord.Documents.Open(“YOUR DOCUMENT FULL PATH NAME”, PasswordDocument:=strPassword ) Catch ex As Exception Msgbox (“Cannot […]

Key down event in panel control

Posted on November 23rd, 2015 by Amrita Dash

There is no key down event in .NET panel control. The reason behind this is , panel does not get focus and cannot receive any windows message from keyboard. The controls which get focused can have handlers for different keyboard events such as key_up , key_down, key_press. The following is workaround for handling keyboard event […]

Getting installation path in installer class

Posted on November 23rd, 2015 by Amrita Dash

To get the installation directory , where the application got installed we can use the COMMIT event of the installer class.Following are the steps we need to follow for getting the installation path : In the custom actions window of setup project add the primary output for Install, Commit, Uninstall and Rollback. Right click on […]

Multi-threading and cross-thread function invoke

Posted on November 23rd, 2015 by Rabinarayan Biswal

If you have ever worked on a multithreaded application, you probably know that accessing controls of UI thread (like textbox, labels etcc…) directly from another thread is not possible.Acessing UI controls directly from a thread other than UI thread would give you a run-time error. Here is the simple solution to access the UI controls […]

Compact and repair access database using VB.NET

Posted on November 23rd, 2015 by Amrita Dash

The Access DB tools provide a way to compact and repair access database.We can achieve the same thing through code in VB.NET using the following steps. 1. Add a reference to “Microsoft Jet and Replication Objects 2.6 Library” 2. Check if the database is in use , display a warning. [VB.NET CODE STARTS] Dim strAccessDatabasePath […]

Optimizing code for DataBound Controls in .Net | Mindfire Solutions

Posted on November 23rd, 2015 by Shibani Shubhadarshini

This tip demonstrates how to optimize code behind DataBound controls in .NET But first we need to set the DataSource property after setting the ValueMember, DisplayMember of DataBound controls such as ComboBox, LookupEdit, ListBox. Otherwise the control will repopulate as the ValueMember changes. Example in VB.Net: components used : cboClientName is the combobox clientDataTable is […]

Merge Word Documents As Pages Of A Single Document Using VB.NET

Posted on November 23rd, 2015 by Amrita Dash

Lets say we have a word template file and we need to populate the template for “n” number of records and display a single large word document , instead of “n” separate documents. So after creating the separate documents we need to merge them and create a single document with multiple pages. Following code snippet […]

Sorting a user defined collection class

Posted on November 23rd, 2015 by Amrita Dash

This tip demonstrates how to sort a user-defined collection class. Let us say we have a custom class as ClientCollection (collection of Client object) which Inherits System.Collections.CollectionBase. To sort the collection , order by LAST NAME , we can use the following steps. First create a class that implements [IComparer] interface and define the [Compare] […]

Open Outlook folder dialog and select folder using VB.NET

Posted on November 23rd, 2015 by Amrita Dash

Following is the code sample used to display the outlook folder dialog using VB.NET [VB.NET CODE STARTS] Dim objOutlook As Object Dim objOlNamespace As Object Dim objOlFolder As Object objOutlook = CreateObject(“Outlook.Application”) ‘ create outlook application object at the run time objOlNamespace = objOutlook.GetNamespace(“MAPI”) objOlFolder = objContactsNS.PickFolder ‘ displays the folder dialog [VB.NET CODE ENDS] […]

Reading CSV file and extracting records to DataTable in VB.Net

Posted on November 23rd, 2015 by Shibani Shubhadarshini

The following code lines can be used to read a file with .CSV extension and extract all records in the CSV file to a Datatable. We need to pass the complete Folder path and File name of the CVS file as the parameters to the function which will return a datatable with records from CVS […]

Creating an Excel sheet from a CSV file in VB.Net

Posted on November 23rd, 2015 by Shibani Shubhadarshini

The following code lines are useful to create an Excel sheet from a CSV file in VB.Net. We need to pass the complete folder path and csv file name as two parameters. In the code I have given “NewExcelFile.xls” as the file name for new file to be created. This code will generate an NewExcelFile.xls […]

Execute files with [Run as Administrator] option from code

Posted on November 23rd, 2015 by Amrita Dash

Usually due to higher security settings in Windows VISTA ,Windows 7 machines we often need to run our application / setup exe by right clicking on the file and using [Run as Administrator] option. But it can done programmatically too. The sample code given below demonstrates it. [VB.NET CODE STARTS] Dim procInfo As New ProcessStartInfo() […]

GET POSTAL CODE BY USING GOOGLE GEOCODE MAPS API IN VB.NET

Posted on November 23rd, 2015 by Smruti Sahoo

During working with one of my desktop application. I had to implement how to get the exact PostalCode with respect to the Address values supplied, as there are more than one PostalCode exists for a combination of City and StateProvidence for USA country may be for others also. After looking into and trying for getting […]

How to check if MS Word is installed in the machine or not in VB.Net

Posted on November 23rd, 2015 by Smruti Sahoo

This snippet describes how to read the registry in .NET to check if MS Word application is installed. In our developement we often get to show any information in the Word document. But before doing this we need to check whether the MS Word is being installed in the machine or not. Here the below […]

VB.Net code to uninstall any application

Posted on November 23rd, 2015 by Ritesh Kumar

When we install any application, registry of system keeps the unisntall command in the Property : UninstallString So we will get the this cammnad from registry and save in the batch file and execute the batch file. Vb.net code for this as follow: Imports Microsoft.Win32 Imports System.IO Module Module1Dim MyAppStr As String = “MySetup” Dim […]

Simulate keyboard press events programmatically in VB.Net

Posted on November 23rd, 2015 by Shibani Shubhadarshini

Sometimes we need to simulate the keyboard press events programmatically in our application to handle system defined messages and make the application more user friendly. To simulate the keyboard press events for tabbing and Enter key press we can use following code snippets: [Start VB.Net code] Imports System.Threading ‘Declare a thread object to do the […]

Edit & Format the content in the RichTextBox Windows Application through Wordpad

Posted on November 23rd, 2015 by Ashutosh Mahto

This tip is targeted for a specific task in vb.net. The problem, not actually a problem but the task is to edit the content in the RichTextBox of our Windows application through Wordpad and just update our control with that formatted text. Well, the simple way to do this job is 1. Open  the Editor […]

Removing all HTML tags from a string in VB.Net

Posted on November 23rd, 2015 by Smruti Sahoo

At times we face situations in which we may have a big string containing the html tags in it and we need to remove the tags from the text to get the appropriate string as text. We can do it very easily using regular expression comparision as mentioned in the below example :- Example :- […]

To Assign Different Color To List Box Item In VB.NET

Posted on November 23rd, 2015 by Pallavi Praharaj

1.Insert a Listbox named ‘ListBox1’ in a window form named as ‘Form1’ . 2.Change the DrawMode to OwnerDrawVariable. 3.On load event of the Form1 Add items to listbox1 PrivateSub Form1_Load(ByVal sender As System.Object, _ByVal e As System.EventArgs) HandlesMyBase.Load ‘To add items to listbox ListBox1.Items.Add(“Red”) ListBox1.Items.Add(“Orange”) ListBox1.Items.Add(“Purple”) EndSub 4.On listbox drawItem event write this code which […]

How to use Registry keys

Posted on November 23rd, 2015 by Pallavi Praharaj

Developers have always found the windows registry to be a suitable place for storing application specific information and configuration settings. The popularity of the registry can be attributed to the fact that: (a) registry access is faster than file access . (b)it is a very secure system-wide data repository. A folder in the registry is […]

Add installation path in registry

Posted on November 23rd, 2015 by Ritesh Kumar

When we will create installer of any application by default it will not write the installation path (InstallLocation) in the registry when we will install that installer. For this we have to insert the InstallLocation in the CustomAction table of msi database. Step 1: and we have saved it at c:\app folder. Create a vb […]

To Get Directions between two locations

Posted on November 23rd, 2015 by Smruti Sahoo

We can get various details on the directions between two locations as XML like, total distance, total time taken by using various travel modes like(driving, cycling and walking etc.), all the way points and details of how to get there with directions. The code below explains how to send the web request and receive a […]

Access database table and Sql database table using Linq

Posted on November 23rd, 2015 by Tapaswini Mohanty

Problem: We need to join a table from an access database and another from an sql database and display the result in a gridview in .net. Solution: STEP 1: Add a dataset to the project. Lets name the DataSet as DSEmployee. STEP 2: Add new connections in server explorer for the access database and sqlserver […]

How to Lock And Unlock a Folder through Code in VB.NET

Posted on November 23rd, 2015 by Pallavi Praharaj

This code can be used to lock and unlock a selected folder.It mainly used for authentication purpose. 1.Make a window form which contains a textbox named as txtbxBrowseFolderName,3 buttons names as btnBrowse, btnLock, btnUnlock. 2.Insert FolderBrowserDialog1 control.. 3.Insert the following Namespace (a)Imports System.Security.AccessControl (b)Imports System.IO 4.Then insert the following piece of code. PrivateSub btnBrowse_Click(ByVal sender […]

How To Highlight A Row On Selection In Repeater Control

Posted on November 23rd, 2015 by Ashish Kumar

While working with the repeater control I found myself in a scenario where I have a button in the repeater for every column and on the click of that button I need to change the color(highlight) of that row. It’s a very usual case where we need to prepopulate some controls from the databound controls […]

Programatically creating and fetching controls in TablelayoutPanel in Windows application.

Posted on November 23rd, 2015 by Soumya Patnaik

Tablelayoutpanel can arrange the controls in the cells by defining the column and row number. We can add controls by defining the column and row Number. Add a TableLayoutPanel control in the form and name it as “TablelayoutPnl”. Dim IDLbl As New Label IDLbl.Name = “ID” IDLbl.Size = New System.Drawing.Size(10, 17) IDLbl.Text = “Test” Dim […]

Disable row selection as well as the whole row in DevExpress gridview, based on the cell value in IE and Firefox.

Posted on November 23rd, 2015 by Tapaswini Mohanty

The following tip demonstrates how to enable or disable a row based upon one of its column value Let us say we want to disable the whole row if OnHand column value of ASPXGridview is 0. 1.by handling ASPXGridview_HtmlRowCreated event of ASPXGridview. Protected Sub ASPXGridview_HtmlRowCreated(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs) Handles ASPXGridview.HtmlRowCreated If […]

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)> […]

Ways to parse an HTML document text

Posted on November 23rd, 2015 by Tapaswini Mohanty

This tip shows how we can parse an HTML document using HTMLDocumentClass and Regular Expression Problem: We need to parse a html document and get only the style element from the whole html document text. Lets say our html document is as below: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml” > <head> <title>My […]

Change Border Color of a Windows Form in VB.NET

Posted on November 23rd, 2015 by Kumari Vandana

Windows form has its default blue color form border style.We can customize its look and feel. Following are the steps : 1.In form’s property window set ‘FormBorderStyle’ to None.. 2.Now we need to paint the form border using any color we want. (a) Declare some variables ‘The color and the width of the border. Private […]