Dear Friends following article will help you to under to understand the stream class in .NET
Streams are another very common type because they are the means for reading from and writing to the disk and communicating across the network. The System.IO.Stream type is the base type for all task-specific stream types. Table 1-5 shows some of the most commonly used stream types. In addition, network streams are found in the System.Network.Sockets namespace, and encrypted streams are found in the System.Security.Cryptography namespace.
Table 1-5: Common Stream Types System.IO Type
Use to
FileStream
Create a base stream used to write to or read from a file
MemoryStream
Create a base stream used to write to or read from memory
StreamReader
Read data from the stream
StreamWriter
Write data to the stream
The simplest stream classes are StreamReader and StreamWriter, which enable you to read and write text files. You can pass a filename as part of the constructor, enabling you to open a file with a single line of code. After you have processed a file, call the Close method so that the file does not remain locked. The following code, which requires the System.IO namespace, demonstrates how to write to and read from a text file:
' VB
' Create and write to a text file
Dim sw As StreamWriter = New StreamWriter("text.txt")
sw.WriteLine("Hello, World!")
sw.Close
' Read and display a text file
Dim sr As StreamReader = New StreamReader("text.txt")
Console.WriteLine(sr.ReadToEnd)
sr.Close
// C#
// Create and write to a text file
StreamWriter sw = new StreamWriter("text.txt");
sw.WriteLine("Hello, World!");
sw.Close();
// Read and display a text file
StreamReader sr = new StreamReader("text.txt");
Console.WriteLine(sr.ReadToEnd());
sr.Close();
Wednesday, May 27, 2009
Saturday, May 23, 2009
DIagramatic Discription of DOT NET FrameWork
Dear Friends
I found Some of the Pictures which will give idea about what DOT NET is so here it is.

----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------

Hope these might help....................................
I found Some of the Pictures which will give idea about what DOT NET is so here it is.

----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------

Hope these might help....................................
Wednesday, May 20, 2009
VB.NET Interview Series Part 2
Dear Friends
As I have promised here comes the second lot of VB.NET Interview Questions
Q7 : What is .NET?
Ans :- .NET is the development platform which provides advance features facilities for Windows and Web Application development. Dot NET acts as a middle ware between operating system and the .NET Application . The main advantage of dot net is that it's component can talk to each other regard less of the fact in which language they are created.
The two main components are
1.CLR(Common Language Runtime)
2.Frame Work base Libraries
CLR Performs task of Converting IL Code into Native Code .
The other component like .NET framework Case Class acts as a service to be provided to the .NET application.
Q8 : What is the Diff b/w String and StringBuilder?
Ans :- String is mutable means if you want to concatenate string into existing string, the framework copies both existing data into memory ,deletes the existing string and reads the data in new string . This operation hence is very resource consuming for lengthy string concatenation.
String builde is immutable means while adding one more char at the end of string it directly upend the string without removing original string .
(NOTE :- For it's clarification I have posted one article on this blog by the name String Builder in which how it works and how StringBuilder is better then String is explained with the help of an example.)
Q9 : What is the diff. b/w web.config file and machine.Config file ?
Ans : The settings made in web.config file are applied to the particular web application only where as the settings of the machine.cofig file are applied to the whole asp.net application.
Q10 : What is Jagged array?

Fig 1
A jagged array is the array which can have fixed rows but will have diff no of col per row as shown in the Fig 1.
A two dimensional jagged array can be thought of as a table where each row can be thought of as a table where families are the rows and family members are Columns
Syntax(To define) :- Dim Myarray(9)() As Integer
there are two ways of defining jagged array.
Method 1- Dim Myarray1() As Integer = {1,2,3}
Dim Myarray1() As Integer = {4,5}
Dim all_values ()() As Integer = {Myarray1,Myarray2}
Method 2- Dim all_Values()() As Integer = {New Integer () {1,2,3} ,New Integer{4,5}}
As I have promised here comes the second lot of VB.NET Interview Questions
Q7 : What is .NET?
Ans :- .NET is the development platform which provides advance features facilities for Windows and Web Application development. Dot NET acts as a middle ware between operating system and the .NET Application . The main advantage of dot net is that it's component can talk to each other regard less of the fact in which language they are created.
The two main components are
1.CLR(Common Language Runtime)
2.Frame Work base Libraries
CLR Performs task of Converting IL Code into Native Code .
The other component like .NET framework Case Class acts as a service to be provided to the .NET application.
Q8 : What is the Diff b/w String and StringBuilder?
Ans :- String is mutable means if you want to concatenate string into existing string, the framework copies both existing data into memory ,deletes the existing string and reads the data in new string . This operation hence is very resource consuming for lengthy string concatenation.
String builde is immutable means while adding one more char at the end of string it directly upend the string without removing original string .
(NOTE :- For it's clarification I have posted one article on this blog by the name String Builder in which how it works and how StringBuilder is better then String is explained with the help of an example.)
Q9 : What is the diff. b/w web.config file and machine.Config file ?
Ans : The settings made in web.config file are applied to the particular web application only where as the settings of the machine.cofig file are applied to the whole asp.net application.
Q10 : What is Jagged array?

Fig 1
A jagged array is the array which can have fixed rows but will have diff no of col per row as shown in the Fig 1.
A two dimensional jagged array can be thought of as a table where each row can be thought of as a table where families are the rows and family members are Columns
Syntax(To define) :- Dim Myarray(9)() As Integer
there are two ways of defining jagged array.
Method 1- Dim Myarray1() As Integer = {1,2,3}
Dim Myarray1() As Integer = {4,5}
Dim all_values ()() As Integer = {Myarray1,Myarray2}
Method 2- Dim all_Values()() As Integer = {New Integer () {1,2,3} ,New Integer{4,5}}
Tuesday, May 19, 2009
Create Folder on Specific Path
Dear Friends
In this article we will see how to create a Folder on a specific Location using vb.net Code......
Method 1
STEP 1: Create on Console based Application.
STEP 2: Paste the following Code
Imports System.IO
Module Module1
Sub Main()
Dim di As DirectoryInfo = New DirectoryInfo("D:\MyDir")
' Determine whether the directory exists.
If di.Exists Then
' Indicate that it already exists.
Console.WriteLine("Directory already Present")
Console.ReadLine()
Else
' Try to create the directory.
di.Create()
End If
End Sub
End Module
Metod 2
Method 1
STEP 1: Create on Console based Application.
STEP 2: Paste the following Code
Imports System.IO
Module Module1
Sub Main()
'System.IO.Directory.CreateDirectory("D:\MyDirector")
End Sub
End Module
In this article we will see how to create a Folder on a specific Location using vb.net Code......
Method 1
STEP 1: Create on Console based Application.
STEP 2: Paste the following Code
Imports System.IO
Module Module1
Sub Main()
Dim di As DirectoryInfo = New DirectoryInfo("D:\MyDir")
' Determine whether the directory exists.
If di.Exists Then
' Indicate that it already exists.
Console.WriteLine("Directory already Present")
Console.ReadLine()
Else
' Try to create the directory.
di.Create()
End If
End Sub
End Module
Metod 2
Method 1
STEP 1: Create on Console based Application.
STEP 2: Paste the following Code
Imports System.IO
Module Module1
Sub Main()
'System.IO.Directory.CreateDirectory("D:\MyDirector")
End Sub
End Module
String Builder
Dear Friends
Following article contains information regarding STRINGBUILDER in VB.NET
String concatenation is one of the commonly used operations among programmers. If you don't handle the string concatenation in .NET properly, it may decrease the performance of an application.
You can concatenate strings in two ways -
* First, traditional way of using string and adding the new string to an existing string. In the .NET Framework, this operation is costly. When you add a string to an existing string, the Framework copies both the existing and new data to the memory, deletes the existing string, and reads data in a new string. This operation may be very resource consuming in lengthy string concatenation operations.
* The second and better way to concatenate strings in .NET is using the StringBuilder class. The StringBuidler class provides the Append method, that inserts a new string to an existing string.
To prove this theory, we will write two routines and both will repeat the same operations. One is using the string class and second is using the StringBuilder class.
Listing 1 shows the routine that uses string class to concatenate strings.
As you can see from Listing 1, I make a loop and concatenate string using the "+" operator. Before I start the loop, I display the start time and when the loop is done, I display the stop time.
// Put user code to initialize the page here
// Concatenation using string
Console.WriteLine("String routine");
string str = string.Empty;
DateTime startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<10; i++)
{
str += i.ToString();
}
DateTime stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
Listing 1
Now let's see the routine that uses the StringBuidler class. As you can see from Listing 2, we do the exact sample operation but this time we use StringBuilder.Append method to concatenate strings.
// Concatenation using StringBuilder
Console.WriteLine("StringBuilder routine");
StringBuilder builder = new StringBuilder();
startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<10; i++)
{
builder.Append(i.ToString());
}
stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
Listing 2
Now let's run the application. You may not notice the difference for the loop from 1 to 10 as the difference is in milliseconds.
But if you change the loop as following:
for(int i=0; i<10000; i++)
You will notice the difference in seconds .
What about changing loop to the following?
for(int i=0; i<100000; i++)
Now you will see a big difference. This time the difference is in minutes.
Well, that was just time. Every time you add two strings using + operator, a new string allocation is reserverd in memory and used for this new string. So let's say, you are adding strings 100 times using + operator, there will be 100 new memory allocations. In case of StringBuilder, there will only be one memory allocation.
Recommendation
If you have to concatenate a string more than 10 times, it's better to use StringBuilder.
Sample Code
So be cautious when concatenating strings more than just once. Here is the complete listing of the sample code:
using System;
using System.Text;
namespace StringBuilderSamp
{
class Class1
{
static void Main()
{
// Concatenation using string
Console.WriteLine("String routine");
string str = string.Empty;
DateTime startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<100000; i++)
{
str += i.ToString();
}
DateTime stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
// Concatenation using StringBuilder
Console.WriteLine("StringBuilder routine");
StringBuilder builder = new StringBuilder();
startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<100000; i++)
{
builder.Append(i.ToString());
}
stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
}
}
}
Following article contains information regarding STRINGBUILDER in VB.NET
String concatenation is one of the commonly used operations among programmers. If you don't handle the string concatenation in .NET properly, it may decrease the performance of an application.
You can concatenate strings in two ways -
* First, traditional way of using string and adding the new string to an existing string. In the .NET Framework, this operation is costly. When you add a string to an existing string, the Framework copies both the existing and new data to the memory, deletes the existing string, and reads data in a new string. This operation may be very resource consuming in lengthy string concatenation operations.
* The second and better way to concatenate strings in .NET is using the StringBuilder class. The StringBuidler class provides the Append method, that inserts a new string to an existing string.
To prove this theory, we will write two routines and both will repeat the same operations. One is using the string class and second is using the StringBuilder class.
Listing 1 shows the routine that uses string class to concatenate strings.
As you can see from Listing 1, I make a loop and concatenate string using the "+" operator. Before I start the loop, I display the start time and when the loop is done, I display the stop time.
// Put user code to initialize the page here
// Concatenation using string
Console.WriteLine("String routine");
string str = string.Empty;
DateTime startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<10; i++)
{
str += i.ToString();
}
DateTime stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
Listing 1
Now let's see the routine that uses the StringBuidler class. As you can see from Listing 2, we do the exact sample operation but this time we use StringBuilder.Append method to concatenate strings.
// Concatenation using StringBuilder
Console.WriteLine("StringBuilder routine");
StringBuilder builder = new StringBuilder();
startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<10; i++)
{
builder.Append(i.ToString());
}
stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
Listing 2
Now let's run the application. You may not notice the difference for the loop from 1 to 10 as the difference is in milliseconds.
But if you change the loop as following:
for(int i=0; i<10000; i++)
You will notice the difference in seconds .
What about changing loop to the following?
for(int i=0; i<100000; i++)
Now you will see a big difference. This time the difference is in minutes.
Well, that was just time. Every time you add two strings using + operator, a new string allocation is reserverd in memory and used for this new string. So let's say, you are adding strings 100 times using + operator, there will be 100 new memory allocations. In case of StringBuilder, there will only be one memory allocation.
Recommendation
If you have to concatenate a string more than 10 times, it's better to use StringBuilder.
Sample Code
So be cautious when concatenating strings more than just once. Here is the complete listing of the sample code:
using System;
using System.Text;
namespace StringBuilderSamp
{
class Class1
{
static void Main()
{
// Concatenation using string
Console.WriteLine("String routine");
string str = string.Empty;
DateTime startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<100000; i++)
{
str += i.ToString();
}
DateTime stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
// Concatenation using StringBuilder
Console.WriteLine("StringBuilder routine");
StringBuilder builder = new StringBuilder();
startTime = DateTime.Now;
Console.WriteLine("Start time:" + startTime.ToString());
for(int i=0; i<100000; i++)
{
builder.Append(i.ToString());
}
stopTime = DateTime.Now;
Console.WriteLine("Stop time:" + stopTime.ToString());
}
}
}
VB.NET Interview Questions Series 1
Dear Friends
From here on wards I am starting a new Series of Interview Questions and this series will be found on all of my blogs ,
http://learning-mysql.blogspot.com/
http://explore-aspnet.blogspot.com/
http://deepvbnet.blogspot.com/
Hope this may help those who are seeking for new Job,
If any of you found one of my answers as inappropriate I will really appreciate the correct answer and and if any one of you guys are looking for some question which you won't found on blog you can put that on any of Question series Comments area or can always mail me at
1.akashazad@hotmail.com"
2.akashazad@gmail.com"
So here Come the very first Part
VB.NET Interview Questions
Q1. What are the Benifites of using Class Library?
Ans :- Simple ! Why do we have public library? B/c once book is written, many people can subscribe to it and reuse it again & again.
In the same way once you ceate your own class library which have multiple function and procedures they can be published for your own use, or rewriting or performing copying of Code .
Q2. Which is the base class of .NET?
Ans :- System.Object
System is the Name space
Q3. What keyboard Should you use if you don’t want your class to be inherited?
Ans :- For Vb.NET
a. Class NonInheritable
b. Method Notoverridable
And in C# use sealed
Q4. What is IL?
Ans :- When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be run, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture. When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type’s members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.
Q 5. Explain the Diff and similarities between a class and a structure in VB.NET?
Ans : Similarity
a. Both are User defined Types.
b. Both are temple of the object.
c. Both contains members like methods, Properties, fields and use Constructor for initialize.
d. Both of them Inherits from System.Object
Differences
a. Classes are Reference Types where as Structures are Value Types.
Q 6. What is implicit Type casting and Explicit Type Casting ?
Ans : Implicit Type Casting allow conversion without any loss of Data and it should be done when there is no possibility of loss of data.
But There is loss of data Explicit type Casting must be done.
Ex:- Implicit Type Casting
Sub Main()
Dim I as integer
Dim J as double
J= 123.12332
I=D
Writeline(“Integer Value of ” &I)
Print (Result)
I = 132
End Sub
Explicit Type Casting
Sub Main()
Dim I as integer
Dim J as double
J= 123.12332
D =CType(D,I)
Writeline(“Integer Value of ” &I)
Print (Result)
I = 132.12332
End Sub
From here on wards I am starting a new Series of Interview Questions and this series will be found on all of my blogs ,
http://learning-mysql.blogspot.com/
http://explore-aspnet.blogspot.com/
http://deepvbnet.blogspot.com/
Hope this may help those who are seeking for new Job,
If any of you found one of my answers as inappropriate I will really appreciate the correct answer and and if any one of you guys are looking for some question which you won't found on blog you can put that on any of Question series Comments area or can always mail me at
1.akashazad@hotmail.com"
2.akashazad@gmail.com"
So here Come the very first Part
VB.NET Interview Questions
Q1. What are the Benifites of using Class Library?
Ans :- Simple ! Why do we have public library? B/c once book is written, many people can subscribe to it and reuse it again & again.
In the same way once you ceate your own class library which have multiple function and procedures they can be published for your own use, or rewriting or performing copying of Code .
Q2. Which is the base class of .NET?
Ans :- System.Object
System is the Name space
Q3. What keyboard Should you use if you don’t want your class to be inherited?
Ans :- For Vb.NET
a. Class NonInheritable
b. Method Notoverridable
And in C# use sealed
Q4. What is IL?
Ans :- When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be run, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture. When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type’s members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.
Q 5. Explain the Diff and similarities between a class and a structure in VB.NET?
Ans : Similarity
a. Both are User defined Types.
b. Both are temple of the object.
c. Both contains members like methods, Properties, fields and use Constructor for initialize.
d. Both of them Inherits from System.Object
Differences
a. Classes are Reference Types where as Structures are Value Types.
Q 6. What is implicit Type casting and Explicit Type Casting ?
Ans : Implicit Type Casting allow conversion without any loss of Data and it should be done when there is no possibility of loss of data.
But There is loss of data Explicit type Casting must be done.
Ex:- Implicit Type Casting
Sub Main()
Dim I as integer
Dim J as double
J= 123.12332
I=D
Writeline(“Integer Value of ” &I)
Print (Result)
I = 132
End Sub
Explicit Type Casting
Sub Main()
Dim I as integer
Dim J as double
J= 123.12332
D =CType(D,I)
Writeline(“Integer Value of ” &I)
Print (Result)
I = 132.12332
End Sub
Tuesday, August 5, 2008
Play .wav/.mp3(Songs)/Vedio(Movies)
Hello Friends in this article we will see three things
1. How to play “.wav” Files?
2. How to play “.mp3” Files? (i.e. How to play Songs?)
3. How to play Video Files? (i.e. How to play Movies?)
First we will see to play wave files (i.e. “.wav” files)(U guys can found some of the .wav files on your system as well they are mostly in “C:\Windows\Media” in this folder U can found all the sound made by your Windows Operating system while doing diff. things.)
Create a new Project by clicking on FILE --> NEW PROJECT and selecting a new Windows Project.
A new Form will come in front of U. Now we need to add few Controls to it,
1. Two Button control. (btnPlay, btnOpen)
2. One Label Control. (Label1)
3. One Text Box Control. (txtFileNm)
4. One OpenFileDialog Control. (OpenFileDialog1)
Make Your Form Look like mine

Make the Filter Property of OpenFileDialoge to “WAV Files|*.wav”
Now just paste the code on your code window.
Imports System.Media
Public Class Form1
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtFileNm.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
If txtFileNm.Text <> String.Empty Then
Dim wavPlayer As SoundPlayer = New SoundPlayer()
wavPlayer.SoundLocation = txtFileNm.Text
AddHandler wavPlayer.LoadCompleted, AddressOf wavPlayer_LoadCompleted
wavPlayer.LoadAsync()
End If
End Sub
Private Sub wavPlayer_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
CType(sender, System.Media.SoundPlayer).Play()
End Sub
End Class
Now click on to browse button u will see the similar browsing dialog box which we normal see when we browse some file in windows.
Now just select any .wav file u have or u can found some in the folder I have already told U .Select the file and click Ok button and then hit the play button to here the sound.
____________________________________________________________________________
Now here is the thing for which most of U guys are bearing for this long i.e how to Play a song using your application or how to play “.mp3” file.
This one is simpler; create a new project as told earlier
To a new Form we add few Controls,
1. One Button control. (btnOpen/Play)
2. One OpenFileDialog Control. (OpenFileDialog1)
3. One WindowsMediaPlayer Control.
Make Your Form Look like mine

Note : This windowsMediaPlayer u can not find in your tool box for that you have to do the following
1. Right click on to the tool Box and click on to the choose items (As shown below.)

Now after a weight of few seconds new window (as shown below) will pop up.

On to this select the COM Component (Windows Media Player) (as shown above) and hit OK.
Then a new windows media player control is ready to be added to your Project . Now just double click on to the control and it will be added to your project.
Now just paste the code in your project and see(I mean hear) the magic.
Imports System.Media
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Const DATA_FILE_EXTENSION As String = ".mp3"
Dim dlgFileDialog As New OpenFileDialog
With dlgFileDialog
.Filter = DATA_FILE_EXTENSION & _
" files (*" & DATA_FILE_EXTENSION & "|*" & DATA_FILE_EXTENSION
.FilterIndex = 1
.RestoreDirectory = True
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
'Play the sound file
Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName
End If
End With
End Sub
End Class
_____________________________________________________________________________-
In this portion we will see how to play a movie using vb.net
Just create a new project as told earlier
This will be the simplest .
On to the form add a single button hence I am not giving u the visual this time.
Now the new thing to this will be that u need to add the reference
Don’t panic every thing will be told here only have patience for some more time,just follow the steps
1. Click on the Project Menu --> Add Reference
2. New window will be open and now in .net Reference U can found “Microsoft.DirectX.AudioVedioPlayback” (As shown below)

Click OK to add the Reference to your project.
Now that’s it just pass the code and pass the path of your video file where required
Imports Microsoft.DirectX.AudioVideoPlayback
Public Class Form1
Dim WithEvents Vid As New Microsoft.DirectX.AudioVideoPlayback.Video("Your video file Path")
Public Sub Play()
If Vid Is Nothing Then Return
Vid.Play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call Play()
End Sub
End Class
---------------------------------------------------------------------------------------------------------------------
Thanx for your patience ,in the end I would like to say that all these three projects can be done in one project but for the sake of simplicity I make it in three projects
With some more code and and some more user control one can have your very own media player.well this is not easy as I am saying but it can be done and in fact I am working on it as soon as it is done it will be on my Blog .
Till then HAPPY CODING and God Bless.
1. How to play “.wav” Files?
2. How to play “.mp3” Files? (i.e. How to play Songs?)
3. How to play Video Files? (i.e. How to play Movies?)
First we will see to play wave files (i.e. “.wav” files)(U guys can found some of the .wav files on your system as well they are mostly in “C:\Windows\Media” in this folder U can found all the sound made by your Windows Operating system while doing diff. things.)
Create a new Project by clicking on FILE --> NEW PROJECT and selecting a new Windows Project.
A new Form will come in front of U. Now we need to add few Controls to it,
1. Two Button control. (btnPlay, btnOpen)
2. One Label Control. (Label1)
3. One Text Box Control. (txtFileNm)
4. One OpenFileDialog Control. (OpenFileDialog1)
Make Your Form Look like mine

Make the Filter Property of OpenFileDialoge to “WAV Files|*.wav”
Now just paste the code on your code window.
Imports System.Media
Public Class Form1
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtFileNm.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
If txtFileNm.Text <> String.Empty Then
Dim wavPlayer As SoundPlayer = New SoundPlayer()
wavPlayer.SoundLocation = txtFileNm.Text
AddHandler wavPlayer.LoadCompleted, AddressOf wavPlayer_LoadCompleted
wavPlayer.LoadAsync()
End If
End Sub
Private Sub wavPlayer_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
CType(sender, System.Media.SoundPlayer).Play()
End Sub
End Class
Now click on to browse button u will see the similar browsing dialog box which we normal see when we browse some file in windows.
Now just select any .wav file u have or u can found some in the folder I have already told U .Select the file and click Ok button and then hit the play button to here the sound.
____________________________________________________________________________
Now here is the thing for which most of U guys are bearing for this long i.e how to Play a song using your application or how to play “.mp3” file.
This one is simpler; create a new project as told earlier
To a new Form we add few Controls,
1. One Button control. (btnOpen/Play)
2. One OpenFileDialog Control. (OpenFileDialog1)
3. One WindowsMediaPlayer Control.
Make Your Form Look like mine

Note : This windowsMediaPlayer u can not find in your tool box for that you have to do the following
1. Right click on to the tool Box and click on to the choose items (As shown below.)

Now after a weight of few seconds new window (as shown below) will pop up.

On to this select the COM Component (Windows Media Player) (as shown above) and hit OK.
Then a new windows media player control is ready to be added to your Project . Now just double click on to the control and it will be added to your project.
Now just paste the code in your project and see(I mean hear) the magic.
Imports System.Media
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Const DATA_FILE_EXTENSION As String = ".mp3"
Dim dlgFileDialog As New OpenFileDialog
With dlgFileDialog
.Filter = DATA_FILE_EXTENSION & _
" files (*" & DATA_FILE_EXTENSION & "|*" & DATA_FILE_EXTENSION
.FilterIndex = 1
.RestoreDirectory = True
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
'Play the sound file
Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName
End If
End With
End Sub
End Class
_____________________________________________________________________________-
In this portion we will see how to play a movie using vb.net
Just create a new project as told earlier
This will be the simplest .
On to the form add a single button hence I am not giving u the visual this time.
Now the new thing to this will be that u need to add the reference
Don’t panic every thing will be told here only have patience for some more time,just follow the steps
1. Click on the Project Menu --> Add Reference
2. New window will be open and now in .net Reference U can found “Microsoft.DirectX.AudioVedioPlayback” (As shown below)

Click OK to add the Reference to your project.
Now that’s it just pass the code and pass the path of your video file where required
Imports Microsoft.DirectX.AudioVideoPlayback
Public Class Form1
Dim WithEvents Vid As New Microsoft.DirectX.AudioVideoPlayback.Video("Your video file Path")
Public Sub Play()
If Vid Is Nothing Then Return
Vid.Play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call Play()
End Sub
End Class
---------------------------------------------------------------------------------------------------------------------
Thanx for your patience ,in the end I would like to say that all these three projects can be done in one project but for the sake of simplicity I make it in three projects
With some more code and and some more user control one can have your very own media player.well this is not easy as I am saying but it can be done and in fact I am working on it as soon as it is done it will be on my Blog .
Till then HAPPY CODING and God Bless.
Subscribe to:
Posts (Atom)