Using SQLite with c#.net

This tutorial covers how to use Sqlite database using c#.

What is SQLITE?
SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private. SQLite is the most widely deployed database in the world with more applications than we can count, including several high-profile projects.

… 

 

Listing All the Installed Softwares in Computer using .Net

We will be Accomplishing using the Windows Registry.

Main Registry to work here is : “SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products”

Just Write Down The Following Code the Form’s Loading Event (Form Contains No Control):

C#.NET

private void Form1_Load(object sender, EventArgs e)
{
string SoftwareKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
RegistryKey rk = default(RegistryKey);
rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);
//string skname = null;
string sname = string.Empty;

ListView ListView1 = new ListView();
this.Controls.Add(ListView1);
ListView1.Dock = DockStyle.Fill;

ListView1.View = View.Details;
ListView1.Columns.Add("Installed Software");

foreach (string skname in rk.GetSubKeyNames())
{

try
{
sname = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("DisplayName").ToString();
ListView1.Items.Add(sname);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);


}

VB.NET

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim SoftwareKey As String = "SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products"
Dim rk As RegistryKey
rk = Registry.LocalMachine.OpenSubKey(SoftwareKey)
Dim skname As String
Dim sname As String = String.Empty

Dim ListView1 As New ListView
Me.Controls.Add(ListView1)
ListView1.Dock = DockStyle.Fill

ListView1.View = View.Details
ListView1.Columns.Add("Installed Software")

For Each skname In rk.GetSubKeyNames
Try
sname = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("DisplayName")
ListView1.Items.Add(sname)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next

ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

End Sub

Output:

Downloads:


vb.net : Download
c#.net : Download

 

Understanding StopWatch Class in c#

Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. In a typical Stopwatch scenario, you call the Startmethod, then eventually call the Stop method, and then you check elapsed time using the Elapsed property. (From MSDN)


Let say i want to find out Total Time a Process has been Running. 
Like
1. How many Minutes or Second it took to insert 1000 record in Database?
2. How many time it took to update the Database ? etc ..


I provide a very Basic Example with a Console Application ..


The Stopwatch Class has two Primary Methods 1. Start() 2. Stop() and One Property that is Elapsed .


The Code:



using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace StopWatchExample
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
Console.WriteLine("Stop Watch Start....n");
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i + "n");
}
sw.Stop();
Console.WriteLine("Stop Watch Stopped:");
Console.WriteLine("Total Time: {0}", sw.Elapsed);
Console.ReadLine();
}
}
}

As You can See I have started our Stopwatch Just Before My loop has started.
Now the Loop will Do its work ..
After That As Soon As we are out sw.Stop has been Called.

I have Just Recorded The Timing The Loop Took To Complete.

The Output Will Look SomeThing Like These:

 

Embeding Firefox Brower (Gecko Engine) in C# using GeckoFX

Ever Thought if it was possible to not WebBrower control and use the Firefox Browser in your c# window Application…??

Yes ,, It is possible using GeckoFx wrapper class for  C#.net and vb also.

You will need the Followings:

1. GeckoFx Wrapper [Download]
2. Xul Runner [Download] (Download the zip file from here)

How to:

1.   Now Extract Skybound.GeckoFX.bin.v1.9.1.0.zip (First download).
      You will find Skybound.Gecko.dll and that’s what we need.
2.   Now create a Project and name is GeckoFxcsharpBorwer or anything you like.
3.   Now  add the reference of the above dll and also add that to your toolbox.
4.   Now Exctract the Second downloaded file (xulrunner-1.9.1.2.en-US.win32.zip). and you will find xulrunner . This is the path to xulrunner runtime.
5.   Create a Form Layout Like The Figure Below:

Now The Coding Part:

Our Form’s Constructor:(Providing the Path to XulRunner Runtime)

public Form1()
{
InitializeComponent();
Skybound.Gecko.Xpcom.Initialize("Path To the xulrunner directory [Extracted from the Second Downloaded File]"); // for example "c:\xulrunner\"
}

Form’s Load Event:

private void Form1_Load(object sender, EventArgs e)
{
geckoWebBrowser1.Navigate("www.google.com");
}

Stop Button click Event:

private void btnStop_Click(object sender, EventArgs e)
{
geckoWebBrowser1.Stop();
}

Refresh Button Click Event:

private void btnRefresh_Click(object sender, EventArgs e)
{
geckoWebBrowser1.Refresh();
}

Save Page Button Click Event:

private void btnSavePage_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = " Html File | *.html";
if (sfd.ShowDialog() == DialogResult.OK)
{
geckoWebBrowser1.SaveDocument(sfd.FileName);
}
}

And Now Finally the Output:

That’s All.

Complete Project : GeckoNet

ps: You can easily Add an Addressbar and other stuff

 

Reading Tags From Mp3 Files

In this post i will show you how to read the Tags like Album,Artist,Song Title,Year etc from mp3 , avi , ogg, Asf, Divx, png etc..

You will need Taglib – Sharp Library for this purpose .

Download the Library : http://download.banshee.fm/taglib-sharp/

you will find taglib-sharp.dll That’s what we need.

1. Create a project . Name it something like TagReader
2. Add reference to the taglib-sharp.dll
3. Make a Form look something like  below figure.

Most of the Coding is Understandable so i will put the Whole form’s coding.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TagLib;

namespace TagReadermp3
{
public partial class frmTagReader : Form
{
public frmTagReader()
{
InitializeComponent();
}

private void btnSelect_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Mp3 Files | *.mp3";
if (ofd.ShowDialog() == DialogResult.OK)
{
lblFile.Text = ofd.FileName;
}

}

private void btnRead_Click(object sender, EventArgs e)
{
TagLib.File mp3 = TagLib.File.Create(lblFile.Text);
lblAlbum.Text = mp3.Tag.Album;
lblAritst.Text = GetAllStringsFromArrary(mp3.Tag.AlbumArtists,","); // Tag.AlbumAritst is a string array
lblBitsPerMinute.Text = mp3.Tag.BeatsPerMinute.ToString();
lblComposers.Text = GetAllStringsFromArrary(mp3.Tag.Composers,",");
lblCopyright.Text = mp3.Tag.Copyright;
lblGenre.Text = GetAllStringsFromArrary(mp3.Tag.Genres,",");
lblTitle.Text = mp3.Tag.Title;
lblTrack.Text = mp3.Tag.Track.ToString();
lblYear.Text = mp3.Tag.Year.ToString();
lblLength.Text = mp3.Properties.Duration.ToString();
}

public string GetAllStringsFromArrary(string[] strArray,string strDelimeter)
{
string strFinal = string.Empty;

for (int i = 0; i < strArray.Length ; i++)
{
strFinal += strArray[i];

if (i != strArray.Length - 1)
{
strFinal += strDelimeter;
}
}
return strFinal;


}
}
}

**New Length field added
Here is the Link to Complete Project : Tag Reader (Updated)
TagReader (old)

 
%d bloggers like this: