Senin, 09 Februari 2009

How to do basic file I/O in Visual Basic 2005 or in Visual Basic .NET

SUMMARY
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.

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



Read a text file code

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


-------------------------------------------------
Related :
Barcode-string-encoderVbnet

Changing-backgroundcolor

Trik finding google

Directly-filling control

Date-time format vb2008

Finding google rank

Domain checker phps cript

Foreign key sql2005

Create-insert-tableadapter

Check datagrid

Hapus error handling vb2008

Function2 vb2008

Explorer vb2008

Buat splashscreen vb2008

Foundation in net30

Backup-database-SQL2008

Executing SQL SERVER

Data grid view attending