Convert ASCII values from hex to characters

by Prashant 31. May 2009 00:46

This C# code takes in a list of ASCII values (hexadecimal) and shows the actual characters behind, thus converting hex values to strings.

// An object storing the hex value
string HexValue = "4765656B7065646961";
// An object storing the string value
string StrValue = "";
// While there's still something to convert in the hex string
while (HexValue.Length > 0)
{
    // Use ToChar() to convert each ASCII value (two hex digits) to the actual character
    StrValue += Convert.ToChar(Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
    // Remove from the hex object the converted value
    HexValue = HexValue.Substring(2, HexValue.Length - 2);
}
// Show the converted value
MessageBox.Show(StrValue); 

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

C# | Code Snippets


Printing word documents without showing Print Dialog

by Prashant 30. May 2009 00:09

Just one Click! and documents queued to the printer. The code will provide you the full flexiblity to set the default printer and also to set other word document settings. I used the code to convert the word document to PDF using Adobe PDF printer driver, as I was unable to get the code to convert the word files to PDF using DLLs.Cool

 

Download the code and don't forget to look at the comments.

 

Download: docprntpdf.zip (645.83 kb)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

C#


Populating, Restore and Backup SQL Database using C#

by Prashant 28. May 2009 00:01

You want to add a functionality in your C# application to allow user to select the database to restore and taking backups of the database. C# provides the classes to allow a programmer to achieve this in the application.

 

Before you go and implement this feature in your application, make sure you have added the references of the following namespaces:

1.) Microsoft.SqlServer.Smo

2.) Microsoft.SqlServer.ConnectionInfo

 

Click the below link to download the full application

 

Download: DBBackup.zip (290.99 kb)

 


If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

C#


Import CSV File Into SQL Server Using Bulk Insert

by Prashant 26. May 2009 00:51

You have large data to import to SQL Server, and you have all the data in a CSV File (Comma Seperated Value file). Are you going to map the field one by one? 

OR just use a small function od SQL to import everything in the table. But before you proceed with this you need to map each column of CSV with the one with your table column. Look at the below quick example on how to use the BULK INSERT to import CSV file data into SQL Server.

Step 1: Create a CSV file.

Step 2: Create a table and map the fields accordingly: (Check below screenshot)

 

Here is the CODE:

BULK INSERT TestTable
FROM 'c:\TestData.csv'  -- Full path of the CSV file
WITH
(
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n'   --Use to shift the control to next row
)

 

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , ,

T-SQL


Convert Numbers to Words in C#

by Prashant 24. May 2009 22:18

Use the below code to convert numbers to words and currency to word programatically (Check the code below). Instead you can create a DLL and use it or whatever the way you likeWink

Download the full Code from the below Link:

Usage: 

 

Download Link:

Num2Wrd.cs (8.30 kb)

 

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

C# | Code Snippets


Visit blogadda.com to discover Indian blogs Computers Blogs

About Me

Name of authorPrashant Khandelwal.
Programmer and tech enthusiast. More...

Feeds Subscribe Twitter Facebook Google Plus Linked In Delicious

Badges

MVB

MVP Blog Badge.

HTML5 Powered with CSS3 / Styling, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage

Month List

Blog Stats

414,191 Hits

Adverts

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Creative Commons License