VB.NET

Check if a Program is being installed or not?

16/12/2009 12:11
Private bInstalled As Boolean Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load        Try            Dim oApp As Object = CreateObject("Outlook.Application")         ...

Folder activity in vb.net

20/11/2009 10:40
Watching File/Folder Activity in VB.NET posted ‎‎Sep 18, 2009 1:17 AM‎‎ by thiyagaraaj Mr   [ updated ‎‎Sep 18, 2009 1:19 AM‎‎ ] Contents 1 Introduction 2 Getting...

VB.NET 2003 and 2005 snippets

18/11/2009 14:05
Add 'all' Date/Time Formats to Listbox/Combobox         'Should add all of the available Date and Time formats to a combobox or listbox control.           Dim dateTime As DateTime = New...

Shutdown/Restart/Logoff your PC using TweetMyPC

31/07/2009 15:39
In this article I will show you how you can use Twitter API to Shutdown/Restart/Logoff your PC remotely using VB.net. Compiled version: CodePlex.com Source Code: Codeplex.com Difficulty: Beginner Time Required: 2 hours Cost: Free Software Needed: Visual Basic or Visual C#...

VB.net Forum

Date 01/08/2012

By selvi

Subject vb.net

Reply

wonderful

Date 15/03/2010

By den

Subject combination of fcfs,sjf - OS

Reply

Public Class Form1
Dim a, b, c As Integer
Dim xx, yy As Integer






Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
End

End Sub
Sub we()
If TextBox1.Text.Length > 3 Then
TextBox8.Text = "Arrival Order inputted is higher than 3!"
ElseIf TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Then
TextBox8.Text = "Something is Empty"
Else



If TextBox1.Text = "123" Then
TextBox5.Text = TextBox2.Text
TextBox6.Text = TextBox3.Text
TextBox7.Text = TextBox4.Text
a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = a + (a + b)
x.Text = xx / 3
yy = a + (a + (a + b)) + (a + (a + b) + (a + b + c))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"

ElseIf TextBox1.Text = "321" Then
TextBox5.Text = TextBox4.Text
TextBox6.Text = TextBox3.Text
TextBox7.Text = TextBox2.Text
a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = 0 + c + (c + b)
x.Text = xx / 3
yy = c + (c + (c + b)) + (c + (c + b) + (c + b + a))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"
ElseIf TextBox1.Text = "231" Then
TextBox5.Text = TextBox3.Text
TextBox6.Text = TextBox4.Text
TextBox7.Text = TextBox2.Text

a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = b + (b + c)
x.Text = xx / 3
yy = b + (b + (b + c)) + (b + (c + b) + (b + c + a))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"
ElseIf TextBox1.Text = "312" Then
TextBox5.Text = TextBox4.Text
TextBox6.Text = TextBox2.Text
TextBox7.Text = TextBox3.Text

a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = c + (c + a)
x.Text = xx / 3
yy = c + (c + (c + a)) + (c + (c + a) + (c + a + b))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"
ElseIf TextBox1.Text = "213" Then
TextBox5.Text = TextBox3.Text
TextBox6.Text = TextBox2.Text
TextBox7.Text = TextBox4.Text
a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = b + (b + a)
x.Text = xx / 3
yy = b + (b + (b + a)) + (b + (b + a) + (b + a + c))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"
ElseIf TextBox1.Text = "132" Then
TextBox5.Text = TextBox2.Text
TextBox6.Text = TextBox4.Text
TextBox7.Text = TextBox3.Text
a = TextBox2.Text
b = TextBox3.Text
c = TextBox4.Text
xx = a + (a + c)
x.Text = xx / 3
yy = a + (a + (a + c)) + (a + (a + c) + (a + c + b))
y.Text = yy / 3
TextBox8.Text = "Successful attempt!"
Else
TextBox8.Text = "Wrong Description of the Arrival Order"
End If
End If

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Label19.Text = "."
Label18.Text = "."
Label11.Text = "."
Label10.Text = "."






End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
x.Clear()
y.Clear()


End Sub

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

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Maximum = 100
If ProgressBar1.Value <> ProgressBar1.Maximum Then
ProgressBar1.Value += 20
Else
Call we()
Timer1.Enabled = False
ProgressBar1.Maximum = 0
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text = "" Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox3.Text = "" Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If TextBox4.Text = "" Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim x, y, z, xx, yy, zz As Integer
Dim a, b, c, d, ee, f As Integer

Dim aa, bb, cc, dd As Integer

x = TextBox17.Text
y = TextBox15.Text
z = TextBox13.Text

xx = TextBox16.Text
yy = TextBox14.Text
zz = TextBox12.Text


If x = y = True And y = z = True And z = y = True Then
MsgBox("All Process is Duplicated...")
If xx < yy And xx < zz Then
If yy < zz = True Then
Label15.Text = "P1"
Label16.Text = "P2"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P2"
TextBox7.Text = "P3"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + zz



Else
Label15.Text = "P1"
Label16.Text = "P3"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P3"
TextBox7.Text = "P2"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + yy
End If




ElseIf yy < xx And yy < zz Then
If xx < zz = True Then
Label15.Text = "P2"
Label16.Text = "P1"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P1"
TextBox7.Text = "P3"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + zz
Else
Label15.Text = "P2"
Label16.Text = "P3"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P3"
TextBox7.Text = "P1"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + xx
End If

ElseIf zz < yy And zz < xx Then
If xx < yy = True Then
Label15.Text = "P3"
Label16.Text = "P1"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P1"
TextBox7.Text = "P2"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + yy
Else
Label15.Text = "P3"
Label16.Text = "P2"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P2"
TextBox7.Text = "P1"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + xx
End If










End If


Else


If x = y = True And x = z = False Then
MsgBox("duplicated 1")
If xx < yy = True Then
Label15.Text = "P1"
Label16.Text = "P2"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P2"
TextBox7.Text = "P3"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + zz
Else
Label15.Text = "P2"
Label16.Text = "P1"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P1"
TextBox7.Text = "P3"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + yy
End If
ElseIf x = z = True And x = y = False Then
MsgBox("duplicated 2")
If xx < zz = True Then
Label15.Text = "P1"
Label16.Text = "P3"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P3"
TextBox7.Text = "P2"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + yy

Else
Label15.Text = "P3"
Label16.Text = "P1"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P1"
TextBox7.Text = "P2"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + yy
End If
ElseIf y = z = True And y = x = False Then
MsgBox("duplicated 3")
If yy < zz = True Then
Label15.Text = "P2"
Label16.Text = "P3"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P3"
TextBox7.Text = "P1"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + xx



Else
Label15.Text = "P3"
Label16.Text = "P2"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P2"
TextBox7.Text = "P1"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + xx
End If
Else


If x < y And x < z Then

If y < z = True Then
Label15.Text = "P1"
Label16.Text = "P2"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P2"
TextBox7.Text = "P3"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + zz



Else
Label15.Text = "P1"
Label16.Text = "P3"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P1"
TextBox6.Text = "P3"
TextBox7.Text = "P2"

'here
Label19.Text = x
Label18.Text = x + xx
aa = x + xx
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + yy
End If


ElseIf y < x And y < z Then
If x < z = True Then
Label15.Text = "P2"
Label16.Text = "P1"
Label17.Text = "P3"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P1"
TextBox7.Text = "P3"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + zz
Else
Label15.Text = "P2"
Label16.Text = "P3"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P2"
TextBox6.Text = "P3"
TextBox7.Text = "P1"

'here
Label19.Text = y
Label18.Text = y + yy
aa = y + yy
Label11.Text = aa + zz
bb = aa + zz
Label10.Text = bb + xx
End If

ElseIf z < y And z < x Then
If x < y = True Then
Label15.Text = "P3"
Label16.Text = "P1"
Label17.Text = "P2"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P1"
TextBox7.Text = "P2"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + xx
bb = aa + xx
Label10.Text = bb + yy
Else
Label15.Text = "P3"
Label16.Text = "P2"
Label17.Text = "P1"

'HERE
TextBox5.Text = "P3"
TextBox6.Text = "P2"
TextBox7.Text = "P1"

'here
Label19.Text = z
Label18.Text = z + zz
aa = z + zz
Label11.Text = aa + yy
bb = aa + yy
Label10.Text = bb + xx
End If

End If

End If

End If

End Sub
End Class

Date 07/03/2010

By den

Subject filter listbox for search

Reply

http://www.codeproject.com/KB/vb/listboxsearch.aspx

Date 20/02/2010

By den

Subject text to speech program

Reply

Dim Speech
Speech = CreateObject("sapi.spvoice")
Speech.Speak(TextBox1.Text)

Date 20/02/2010

By den

Subject screenshot

Reply

Public Class FRM_ScreenShot

Private Sub BTN_TakeScreenShot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_TakeScreenShot.Click
Try
Dim path As String = Nothing
Dim SaveFileDialog1 As New SaveFileDialog
With SaveFileDialog1
If .ShowDialog = DialogResult.OK Then
path = .FileName
End If
End With

Dim DirectoryA As String = path & ".jpg"
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim BMP As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
BMP.Save(DirectoryA)
MsgBox("SAVED TO " & DirectoryA, MsgBoxStyle.Information)
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub

End Class

Date 01/02/2010

By den

Subject flat file issue in vb.net

Reply

Reading and writing text files is an essential task in any programming language. Follow this step-by-step approach to working with text files in VB .NET.

Years ago, when I first learned to program in BASIC, I came across a sample program for reading a text file. The OPEN command with the file number looked quite confusing, so I never wrote the program. Later, when I learned Visual Basic, I was shocked to see that the same file operations existed in VB. The basic file-handling commands had not changed; just a few more features had been added.

With Visual Basic .NET, Microsoft introduced a new, object-oriented method for working with files. The System.IO namespace in the .NET framework provides several classes for working with text files, binary files, directories, and byte streams. I will look specifically at working with text files using classes from the System.IO namespace.

Basic methods
Before we jump into working with text files, we need to create a new file or open an existing one. That requires the System.IO.File class. This class contains methods for many common file operations, including copying, deleting, file attribute manipulation, and file existence. For our text file work, we will use the CreateText and OpenText methods.

WEEKLY .NET HOW-TOS

New .NET tutorials updated every Thusday with Cast Your .NET

CreateText
True to its name, the CreateText method creates a text file and returns a System.IO.StreamWriter object. With the StreamWriter object, you can then write to the file. The following code demonstrates how to create a text file:
Dim oFile as System.IO.File
Dim oWrite as System.IO.StreamWriter
oWrite = oFile.CreateText(“C:\sample.txt”)
OpenText

The OpenText method opens an existing text file for reading and returns a System.IO.StreamReader object. With the StreamReader object, you can then read the file. Let’s see how to open a text file for reading:
Dim oFile as System.IO.File
Dim oRead as System.IO.StreamReader
oRead = oFile.OpenText(“C:\sample.txt”)
Writing to a text file

The methods in the System.IO.StreamWriter class for writing to the text file are Write and WriteLine. The difference between these methods is that the WriteLine method appends a newline character at the end of the line while the Write method does not. Both of these methods are overloaded to write various data types and to write formatted text to the file. The following example demonstrates how to use the WriteLine method:
oWrite.WriteLine(“Write a line to the file”)
oWrite.WriteLine() ‘Write a blank line to the file
Formatting the output

The Write and WriteLine methods both support formatting of text during output. The ability to format the output has been significantly improved over previous versions of Visual Basic. There are several overloaded methods for producing formatted text. Let’s look at one of these methods:
oWrite.WriteLine(“{0,10}{1,10}{2,25}”, “Date”, “Time”, “Price”)
oWrite.WriteLine(“{0,10:dd MMMM}{0,10:hh:mm tt}{1,25:C}”, Now(), 13455.33)
oWrite.Close()

The overloaded method used in these examples accepts a string to be formatted and then a parameter array of values to be used in the formatted string. Let’s look at both lines more carefully.

The first line writes a header for our report. Notice the first string in this line is {0,10}{1,10}{2,25}. Each curly brace set consists of two numbers. The first number is the index of the item to be displayed in the parameter array. (Notice that the parameter array is zero based.) The second number represents the size of the field in which the parameter will be printed. Alignment of the field can also be defined; positive values are left aligned and negative values are right aligned.

The second line demonstrates how to format values of various data types. The first field is defined as {0,10:dd MMMM}. This will output today’s date (retrieved using the Now() function) in the format 02 July. The second field will output the current time formatted as 02:15 PM. The third field will format the value 13455.33 into the currency format as defined on the local machine. So if the local machine were set for U.S. Dollars, the value would be formatted as $13,455.33.

Listing A shows the output of our sample code.

Listing A

Date Time Price
22 July 10:58 AM $13,455.33


Reading from a text file
The System.IO.StreamReader class supports several methods for reading text files and offers a way of determining whether you are at the end of the file that's different from previous versions of Visual Basic.

Line-by-line
Reading a text file line-by-line is straightforward. We can read each line with a ReadLine method. To determine whether we have reached the end of the file, we call the Peek method of the StreamReader object. The Peek method reads the next character in the file without changing the place that we are currently reading. If we have reached the end of the file, Peek returns -1. Listing B provides an example for reading a file line-by-line until the end of the file.

Listing B

oRead = oFile.OpenText(-C:\sample.txt")

While oRead.Peek <> -1
LineIn = oRead.ReadLine()

End While

oRead.Close()


An entire file
You can also read an entire text file from the current position to the end of the file by using the ReadToEnd method, as shown in the following code snippet:
Dim EntireFile as String
oRead = oFile.OpenText(“C:\sample.txt”)
EntireFile = oRead.ReadToEnd()

This example reads the file into the variable EntireFile. Since reading an entire file can mean reading a large amount of data, be sure that the string can handle that much data.

One character at a time
If you need to read the file a character at a time, you can use the Read method. This method returns the integer character value of each character read. Listing C demonstrates how to use the Read method.

Listing C

Dim intSingleChar as Integer

Dim cSingleChar as String

oRead = oFile.OpenText(-C:\sample.txt")

While oRead.Peek <> -1

intSingleChar = oRead.Read()

' Convert the integer value into a character

cSingleChar = Chr(intSingleChar)

End While

Tap into the power
We've barely scratched the surface of the new file functionality included in .NET, but at least you have an idea of the power now available in the latest edition of Visual Basic .The abilities of the classes in the System.IO namespace are quite useful, but if you want to continue to use the traditional Visual Basic file operations, those are still supported.

Date 01/02/2010

By den

Subject basic reading and writing text file in vb.net

Reply

Imports System.IO

Reading Text Files:
the easiest way to open a text file is with the System.IO.File.OpenText() method.



Code:'Dim your StreamReader
Dim TextFileStream As System.IO.TextReader



'Load the textfile into the stream
TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")



'Read to the end of the file into a String variable.
Dim MyFileContents As String = TextFileStream.ReadToEnd



'Close the Stream object
TextFileStream.Close()



The above code will open a text file on your C drive called MyTextFile.txt. It will load all of the text into a string variable called MyFileContents.
It won't create a file of that name if it doesn't already exist (and will throw an exception which you should handle - but see later in the FAQ for how to create a new file).




Creating Text Files:



Code:'Dim your Text Writer
Dim TW As System.IO.TextWriter



'Create a Text file and load it into the TextWriter
TW = System.IO.File.CreateText("C:\MyTextFile.txt")



'Write a line
TW.WriteLine("Hello World")



'Write another line
TW.WriteLine("Hello World Again")



'Flush the text to the file
TW.Flush()



'Close the File
TW.Close()




Append to an existing Text file:



Code:'Dim your Stream Writer or Text Writer.
Dim SW As IO.TextWriter



'Open a file for Appending
SW = IO.File.AppendText("C:\MyTextFile.txt")



'Write a line to the bottom of the text file
SW.WriteLine("This is another line added to the bottom of the text file.")



'Flush to the file
SW.Flush()



'Close the object
SW.Close()



Here is how to get a random line from a text file with the smallest code I can think of.
Extracting One Line From a File:



Code:Dim RandomNumber As New Random()
Dim Tr As IO.TextReader = System.IO.File.OpenText("C:\MyTextFile.txt")
Dim FileLines() As String = Split(Tr.ReadToEnd(), vbCrLf)
Tr.Close
Dim MyRandomLine As String = FileLines(RandomNumber.Next(0, UBound(FileLines)))
MsgBox(MyRandomLine)



If you know what line you want to access then you can make it smaller like this :



Code:
Dim Tr As IO.TextReader = System.IO.File.OpenText("C:\MyTextFile.txt")
Dim MyFileLine As String = Split(Tr.ReadToEnd(), vbCrLf)(3)
Tr.Close
MsgBox(MyFileLine)



Note that the above code will return the fourth line from the file. It's zero based, so you would enter (0) for line 1, (1) for line 2 and so on.



So, there's some easy and basic ways of getting text into and out of a text file in .Net. Try It !

Date 01/02/2010

By den

Subject flat file in vb.net

Reply

This step-by-step article shows you how to do six basic file input/output (I/O) operations in Microsoft Visual Basic 2005 or in Microsoft Visual Basic .NET. If you are new to .NET, you will find that the object model for file operations in .NET is similar to the FileSystemObject (FSO) that is popular with many Visual Studio 6.0 developers. To make the transition easier, the functionality that is demonstrated in this article is based on the following Microsoft Knowledge Base article:
186118 (http://support.microsoft.com/kb/186118/ ) How to use FileSystemObject with Visual Basic
You can still use the FileSystemObject in .NET. Because the FileSystemObject is a Component Object Model (COM) component, .NET requires that access to the object be through the Interop layer. .NET generates a wrapper for the component for you if you want to use it. However, the File, FileInfo, Directory, DirectoryInfo classes, and other related classes in the .NET Framework, offer functionality that is not available with the FSO, without the overhead of the Interop layer.
Back to the top
Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:

* Microsoft Windows Server 2003, Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, or Microsoft Windows NT 4.0 Server
* Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET
* Microsoft Visual Studio 2005 Software Development Kit (SDK) Quickstarts or Microsoft Visual Studio .NET SDK Quickstarts

Back to the top
Demonstrated file I/O operations
The examples in this article describe basic file I/O operations. The "Step-by-step example" section describes how to create a sample program that demonstrates the following file I/O operations:

* Read a text file
* Write a text file
* View file information
* List disk drives
* List subfolders
* List files

Read a text file
The following sample code uses a StreamReader class to read the System.ini file. The contents of the file are added to a ListBox control. The try...catch block is used to alert the program if the file is empty. There are many ways to determine when the end of the file is reached; this sample uses the Peek method to examine the next line before reading it.

Dim reader As StreamReader = _
New StreamReader(winDir & "\system.ini")
Try
Me.ListBox1.Items.Clear()
Do
Me.ListBox1.Items.Add(reader.ReadLine)
Loop Until reader.Peek = -1

Catch
Me.ListBox1.Items.Add("File is empty")

Finally
reader.Close()
End Try


Write a text file
This sample code uses a StreamWriter class to create and write to a file. If you have an existing file, you can open it in the same way.

Dim writer As StreamWriter = _
New StreamWriter("c:\KBTest.txt")
writer.WriteLine("File created using StreamWriter class.")
writer.Close()


View file information
This sample code uses a FileInfo object to access a file's properties. Notepad.exe is used in this example. The properties appear in a ListBox control.

Dim FileProps As FileInfo = New FileInfo(winDir & "\notepad.exe")
With Me.ListBox1.Items
.Clear()
.Add("File Name = " & FileProps.FullName)
.Add("Creation Time = " & FileProps.CreationTime)
.Add("Last Access Time = " & FileProps.LastAccessTime)
.Add("Last Write Time = " & FileProps.LastWriteTime)
.Add("Size = " & FileProps.Length)
End With
FileProps = Nothing


List disk drives
This sample code uses the Directory and Drive classes to list the logical drives on a system. For this sample, the results appear in a ListBox control.

Dim dirInfo As Directory
Dim drive As String
Me.ListBox1.Items.Clear()
Dim drives() As String = dirInfo.GetLogicalDrives()
For Each drive In drives
Me.ListBox1.Items.Add(drive)
Next


List subfolders
This sample code uses the GetDirectories method of the Directory class to get a list of folders.

Dim dir As String
Me.ListBox1.Items.Clear()
Dim dirs() As String = Directory.GetDirectories(winDir)
For Each dir In dirs
Me.ListBox1.Items.Add(dir)
Next


List files
This sample code uses the GetFiles method of the Directory class to get a list of files.

Dim file As String
Me.ListBox1.Items.Clear()
Dim files() As String = Directory.GetFiles(winDir)
For Each file In files
Me.ListBox1.Items.Add(file)
Next


Many things can go wrong when a user gains access to files. The files may not exist, the files may be in use, or users may not have rights on the files of folders that they are trying to access. It is important to consider these possibilities when you write code and to handle the exceptions that may be generated.
Back to the top
Step-by-step example

1. In Visual Basic 2005 or in Visual Basic .NET, create a new Windows Application. By default, Form1 is created.
2. Open the code window for Form1.
3. Delete all of the code in the Code-Behind Editor.
4. Paste the following sample code into the Code-Behind Editor window.

Option Strict On
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form
Private winDir As String
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'Windows Form Designer requires this call.
InitializeComponent()

'Add any initialization after the InitializeComponent() call.

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button

'Windows Form Designer requires this call.
Private components As System.ComponentModel.Container

'NOTE: Windows Form Designer requires the following procedure.
'You can use the Windows Form Designer to modify it; however, do not
'use the Code Editor to modify it.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.Button5 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button6 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(272, 64)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(136, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(272, 96)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(136, 23)
Me.Button3.TabIndex = 2
Me.Button3.Text = "Button3"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(16, 16)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(240, 238)
Me.ListBox1.TabIndex = 5
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(272, 128)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(136, 23)
Me.Button4.TabIndex = 3
Me.Button4.Text = "Button4"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(272, 160)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(136, 23)
Me.Button5.TabIndex = 4
Me.Button5.Text = "Button5"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(272, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(136, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(272, 192)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(136, 23)
Me.Button6.TabIndex = 6
Me.Button6.Text = "Button6"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(416, 341)
Me.Controls.AddRange(New System.Windows.Forms.Control() _
{Me.Button6, Me.ListBox1, Me.Button5, Me.Button4, _
Me.Button3, Me.Button2, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.Button1.Text = "Read Text File"
Me.Button2.Text = "Write Text File"
Me.Button3.Text = "View File Information"
Me.Button4.Text = "List Drives"
Me.Button5.Text = "List Subfolders"
Me.Button6.Text = "List Files"
winDir = System.Environment.GetEnvironmentVariable("windir")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
'Demonstrates how to read a file by using StreamReader
'Uses System.ini as an example
'try...catch is used to detect a 0 byte file.
Dim reader As StreamReader = _
New StreamReader(winDir & "\system.ini")
Try
Me.ListBox1.Items.Clear()
Do 'Until reader.Peek = -1
Me.ListBox1.Items.Add(reader.ReadLine)
Loop Until reader.Peek = -1

Catch
Me.ListBox1.Items.Add("File is empty")

Finally
reader.Close()
End Try
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button4.Click
'Demonstrates how to obtain a list of disk drives
Dim dirInfo As Directory
Dim drive As String
Me.ListBox1.Items.Clear()
Dim drives() As String = dirInfo.GetLogicalDrives()
For Each drive In drives
Me.ListBox1.Items.Add(drive)
Next
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button3.Click
'Demonstrates how to access file properties. You can access folder properties
'in the same way. More properties are available through the FileInfo class
'than are demonstrated here.
'You can also use the Directory class to obtain this information.
Dim FileProps As FileInfo = New FileInfo(winDir & "\notepad.exe")
With Me.ListBox1.Items
.Clear()
.Add("File Name = " & FileProps.FullName)
.Add("Creation Time = " & FileProps.CreationTime)
.Add("Last Access Time = " & FileProps.LastAccessTime)
.Add("Last Write TIme = " & FileProps.LastWriteTime)
.Add("Size = " & FileProps.Length)
End With
FileProps = Nothing
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
'Demonstrates how to create and write to a text file
Dim writer As StreamWriter = _
New StreamWriter("c:\KBTest.txt")
writer.WriteLine("File created using StreamWriter class.")
writer.Close()
Me.ListBox1.Items.Clear()
Me.ListBox1.Items.Add("File Written to C:\KBTest.txt")
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button5.Click
'Demonstrates how to get a list of folders (example uses Windows folder)
Dim dir As String
Me.ListBox1.Items.Clear()
Dim dirs() As String = Directory.GetDirectories(winDir)
For Each dir In dirs
Me.ListBox1.Items.Add(dir)
Next
End Sub

Private Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button6.Click
'Demonstrates how to get a list of files (example uses Windows folder)
Dim file As String
Me.ListBox1.Items.Clear()
Dim files() As String = Directory.GetFiles(winDir)
For Each file In files
Me.ListBox1.Items.Add(file)
Next
End Sub
End Class


Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.

For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx (http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx)
For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/ms171843.aspx (http://msdn2.microsoft.com/en-us/library/ms171843.aspx)
5. Press F5 to build and then run the program. Click the buttons to view the different actions. When you view the sample code, you may want to collapse the area named Windows Form Designer Generated Code to hide this code.

Date 16/12/2009

By den

Subject vb.net specifying application prerequisite for running.

Reply

http://www.kirupa.com/net/clickOnce3.htm

Date 21/11/2009

By denz

Subject read html from web control

Reply

At times, you may want to read text or other HTML from the contents of the WebBrowser control. To this end, you can simply place some kind of collection code in the control's DocumentComplete() event. As you may know, the WebBrowser fires this event when it has successfully downloaded the Web page in question. With this in mind, the code might look as follows:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Label1.Caption = WebBrowser1.Document.All("myElem").innerHTML
End Sub

Keep in mind, however, that this code only works for Web pages that don't contain frames. Since the DocumentComplete() event fires once for each frame, the original code might actually try to access a document element that doesn't yet exist (hasn't been rendered in the browser).

To work around this potential pitfall, you can use a conditional to test the pDisp object against the WebBrowser control itself. With multi-frame documents, the WebBrowser fires the DocumentComplete() event one last time after it has loaded all the necessary frames. With this in mind, the following code would accommodate this behavior and fill the Label with the appropriate text under all circumstances.

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.object) Then
Label1.Caption = WebBrowser1.Document.All("myElem").innerHTML
End If
End Sub