We can get the duration of an audio or video file by using the “Shell32” namespace in Visual Studio Dot Net. For that we need to add the reference of “Interop.Shell32.dll” in to our project. And follow the given method in below. By calling the following method with the parameter of full path of file name which might be an audio file or video file we can get the duration of that file.
private string GetDuration(string FileFullPath)
{
string duration = "";
string fName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1);
string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\"));
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(filePath);
Shell32.FolderItem folderItem = folder.ParseName(fName);
if (folderItem != null)
{
duration = folder.GetDetailsOf(folderItem, 21);
}
folderItem = null;
folder = null;
shell = null;
return duration;
}
Thursday, July 30, 2009
Convert .wav to .mp3 using Lame.exe in C#.......!!!!!!!
public void mciConvertWavMP3(string fileName, bool waitFlag)
{
//maxLen is in ms (1000 = 1 second)
string outfile= "-b 32 --resample 22.05 -m m \""+pworkingDir+fileName + "\" \"" + pworkingDir+fileName.Replace(".wav",".mp3")+"\"";
System.Diagnostics.ProcessStartInfo psi=new System.Diagnostics.ProcessStartInfo();
psi.FileName="\""+pworkingDir+"lame.exe"+"\"";
psi.Arguments=outfile;
//psi.WorkingDirectory=pworkingDir;
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Minimized;
System.Diagnostics.Process p=System.Diagnostics.Process.Start(psi);
if (waitFlag)
{
p.WaitForExit();
// wait for exit of called application
}
}
This code will help us to convert .wav file in to .mp3
{
//maxLen is in ms (1000 = 1 second)
string outfile= "-b 32 --resample 22.05 -m m \""+pworkingDir+fileName + "\" \"" + pworkingDir+fileName.Replace(".wav",".mp3")+"\"";
System.Diagnostics.ProcessStartInfo psi=new System.Diagnostics.ProcessStartInfo();
psi.FileName="\""+pworkingDir+"lame.exe"+"\"";
psi.Arguments=outfile;
//psi.WorkingDirectory=pworkingDir;
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Minimized;
System.Diagnostics.Process p=System.Diagnostics.Process.Start(psi);
if (waitFlag)
{
p.WaitForExit();
// wait for exit of called application
}
}
This code will help us to convert .wav file in to .mp3
Getting Drive Volume Information in C#
It's very easy to getting Volume Information of our logical drives by using kernel32.dll
Just copy and paste the following code then run it...that's it. :)
using System.Runtime.InteropServices;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool GetVolumeInformation(string Volume,
StringBuilder VolumeName, uint VolumeNameSize,
out uint SerialNumber, out uint SerialNumberLength, out uint flags,
StringBuilder fs, uint fs_size);
private void Form1_Load(object sender, EventArgs e)
{
uint serialNum, serialNumLength, flags;
StringBuilder volumename = new StringBuilder(256);
StringBuilder fstype = new StringBuilder(256);
bool ok = false;
Cursor.Current = Cursors.WaitCursor;
foreach (string drives in Environment.GetLogicalDrives())
{
ok = GetVolumeInformation(drives, volumename, (uint)volumename.Capacity - 1, out serialNum,
out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1);
if (ok)
{
lblVolume.Text = lblVolume.Text + "\n Volume Information of " + drives + "\n";
lblVolume.Text = lblVolume.Text + "\nSerialNumber of is..... " + serialNum.ToString() + " \n";
if (volumename != null)
{
lblVolume.Text = lblVolume.Text + "VolumeName is..... " + volumename.ToString() + " \n";
}
if (fstype != null)
{
lblVolume.Text = lblVolume.Text + "FileType is..... " + fstype.ToString() + " \n";
}
}
ok = false;
}
Cursor.Current = Cursors.Default;
}
Just copy and paste the following code then run it...that's it. :)
using System.Runtime.InteropServices;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool GetVolumeInformation(string Volume,
StringBuilder VolumeName, uint VolumeNameSize,
out uint SerialNumber, out uint SerialNumberLength, out uint flags,
StringBuilder fs, uint fs_size);
private void Form1_Load(object sender, EventArgs e)
{
uint serialNum, serialNumLength, flags;
StringBuilder volumename = new StringBuilder(256);
StringBuilder fstype = new StringBuilder(256);
bool ok = false;
Cursor.Current = Cursors.WaitCursor;
foreach (string drives in Environment.GetLogicalDrives())
{
ok = GetVolumeInformation(drives, volumename, (uint)volumename.Capacity - 1, out serialNum,
out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1);
if (ok)
{
lblVolume.Text = lblVolume.Text + "\n Volume Information of " + drives + "\n";
lblVolume.Text = lblVolume.Text + "\nSerialNumber of is..... " + serialNum.ToString() + " \n";
if (volumename != null)
{
lblVolume.Text = lblVolume.Text + "VolumeName is..... " + volumename.ToString() + " \n";
}
if (fstype != null)
{
lblVolume.Text = lblVolume.Text + "FileType is..... " + fstype.ToString() + " \n";
}
}
ok = false;
}
Cursor.Current = Cursors.Default;
}
Creation of FileGroups in SQLServer 2005..........
We have to have various file groups for the database if we need to place the partitioned tables on different filegroups.
We can create filegroups in SQL Server by two different ways, one is Alter Command and the second is using Interface.
a) Using the Alter Command
The syntax for Alter Command is,
ALTER DATABASE ADD FILEGROUP
For Example,
Alter Database TestDB ADD FILEGROUP FG1
After adding a filegroup we need to add files to the filegroup.
The Syntax for adding files,
ALTER DATABASE
ADD FILE
(
NAME = , FILENAME = , SIZE = , MAXSIZE = , FILEGROWTH =
)
TO FILEGROUP ;
For Example,
ALTER DATABASE TestDB
ADD FILE
(
NAME = FILE1, FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\FILE1.ndf', SIZE = 1MB, MAXSIZE = 10MB, FILEGROWTH = 1MB
)
TO FILEGROUP FG1;
b) Using the Interface
We can create the filegroup in SQLServer 2005 using Interface by following steps,
1. Select the DB and right click -> Properties
2. Select the Filegroup section and add the necessary details and click the add button.
3. Next we will click on the Files section and add a new file and associate this file to the created filegroup
4. Then finally click on the OK button.
Using these two different ways, we can create filegroups in SQLServer.
We can create filegroups in SQL Server by two different ways, one is Alter Command and the second is using Interface.
a) Using the Alter Command
The syntax for Alter Command is,
ALTER DATABASE ADD FILEGROUP
For Example,
Alter Database TestDB ADD FILEGROUP FG1
After adding a filegroup we need to add files to the filegroup.
The Syntax for adding files,
ALTER DATABASE
ADD FILE
(
NAME = , FILENAME = , SIZE = , MAXSIZE = , FILEGROWTH =
)
TO FILEGROUP ;
For Example,
ALTER DATABASE TestDB
ADD FILE
(
NAME = FILE1, FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\FILE1.ndf', SIZE = 1MB, MAXSIZE = 10MB, FILEGROWTH = 1MB
)
TO FILEGROUP FG1;
b) Using the Interface
We can create the filegroup in SQLServer 2005 using Interface by following steps,
1. Select the DB and right click -> Properties
2. Select the Filegroup section and add the necessary details and click the add button.
3. Next we will click on the Files section and add a new file and associate this file to the created filegroup
4. Then finally click on the OK button.
Using these two different ways, we can create filegroups in SQLServer.
Delegates in C#
An interesting feature in C# is Delegate. Delegates are best complemented as new type of Object in C#. They are also represented as pointer to functions. Technically delegate is a reference type used to encapsulate a method with a specific signature and return type.
There are two types of delegates available in C#.
1. Single Delegate
2. Multi-cast Delegate
Here is the example of delegate as follows,
using System;
namespace testWinApp
{
// 1. Define delegate.
public delegate double UnitConversion(double from);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} // 2. Define handler method.
public static double FeetToInches(double feet)
{
return feet * 12;
}
private void button4_Click(object sender, EventArgs e)
{ // 3. Create delegate instance.
UnitConversion doConversion = new UnitConversion(FeetToInches);
// 4. Use delegate just like a method.
double inch = doConversion(4);
MessageBox.Show(inch.ToString());
}
}
}
Result will be as follows,
There are two types of delegates available in C#.
1. Single Delegate
2. Multi-cast Delegate
Here is the example of delegate as follows,
using System;
namespace testWinApp
{
// 1. Define delegate.
public delegate double UnitConversion(double from);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} // 2. Define handler method.
public static double FeetToInches(double feet)
{
return feet * 12;
}
private void button4_Click(object sender, EventArgs e)
{ // 3. Create delegate instance.
UnitConversion doConversion = new UnitConversion(FeetToInches);
// 4. Use delegate just like a method.
double inch = doConversion(4);
MessageBox.Show(inch.ToString());
}
}
}
Result will be as follows,
Subscribe to:
Posts (Atom)