Input/Output in Visual Basic .NET

Paint QR Code in Visual Basic .NET Input/Output

2
QR Creator In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in Visual Studio .NET applications.
www.OnBarcode.com
Reading QR Code In VB.NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Input/Output
Making Bar Code In VB.NET
Using Barcode printer for .NET Control to generate, create barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Scan Bar Code In Visual Basic .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Exercise 1: Browse the File System
QR Code JIS X 0510 Drawer In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create QR image in VS .NET applications.
www.OnBarcode.com
Paint QR Code JIS X 0510 In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create QR image in ASP.NET applications.
www.OnBarcode.com
In this exercise, you will create a Console application that lists the volumes connected to the computer and then displays the files and folders in the root of the volume. 1. Using Visual Studio, create a new Console Application project. Name the project BrowseFileSystem. 2. Add the System.IO namespace. 3. Write code to display a list of all volumes attached to the computer. For example:
Draw QR Code JIS X 0510 In VS .NET
Using Barcode generation for VS .NET Control to generate, create QR Code JIS X 0510 image in .NET applications.
www.OnBarcode.com
EAN13 Creator In Visual Basic .NET
Using Barcode creation for VS .NET Control to generate, create EAN13 image in .NET applications.
www.OnBarcode.com
' VB Console.WriteLine("Drives:") For Each di As DriveInfo In DriveInfo.GetDrives() Console.WriteLine(" {0} ({1})", di.Name, di.DriveType) Next // C# Console.WriteLine("Drives:"); foreach (DriveInfo di in DriveInfo.GetDrives()) Console.WriteLine(" {0} ({1})", di.Name, di.DriveType);
DataMatrix Drawer In Visual Basic .NET
Using Barcode creation for .NET framework Control to generate, create DataMatrix image in .NET applications.
www.OnBarcode.com
Print Barcode In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
www.OnBarcode.com
4. Next, add code to prompt the user to select a volume to browse and use that input to create a DirectoryInfo instance. For example, the following code prompts the user to type the drive letter associated with the volume:
Printing QR In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create Denso QR Bar Code image in .NET framework applications.
www.OnBarcode.com
Create OneCode In Visual Basic .NET
Using Barcode creation for .NET framework Control to generate, create OneCode image in VS .NET applications.
www.OnBarcode.com
' VB Console.WriteLine() Console.WriteLine("Press a drive letter to view files and folders") Dim drive As ConsoleKeyInfo = Console.ReadKey(True) Dim dir As New DirectoryInfo(drive.Key.ToString() + ":\") // C# Console.WriteLine("\nPress a drive letter to view files and folders"); ConsoleKeyInfo drive = Console.ReadKey(true); DirectoryInfo dir = new DirectoryInfo(drive.Key.ToString() + @":\");
Encoding UCC-128 In None
Using Barcode creator for Font Control to generate, create UCC-128 image in Font applications.
www.OnBarcode.com
Code 128 Maker In VS .NET
Using Barcode printer for .NET Control to generate, create Code 128B image in .NET framework applications.
www.OnBarcode.com
5. Add code to display the folders contained in the root of the selected volume as follows:
Draw Data Matrix 2d Barcode In Objective-C
Using Barcode maker for iPad Control to generate, create DataMatrix image in iPad applications.
www.OnBarcode.com
QR-Code Reader In VS .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
' VB Console.WriteLine() Console.WriteLine("Folders:") For Each dirInfo As DirectoryInfo In dir.GetDirectories() Console.WriteLine(" " + dirInfo.Name) Next // C# Console.WriteLine("\nFolders:"); foreach (DirectoryInfo dirInfo in dir.GetDirectories()) Console.WriteLine(" " + dirInfo.Name);
Encode PDF417 In None
Using Barcode generator for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Decoding Universal Product Code Version A In Visual Studio .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Lesson 1: Working with the File System
Recognizing DataMatrix In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
PDF 417 Creation In None
Using Barcode printer for Office Excel Control to generate, create PDF417 image in Excel applications.
www.OnBarcode.com
6. Finally, add code to display the files contained in the root of the selected volume as follows:
' VB Console.WriteLine() Console.WriteLine("Files:") For Each fi As FileInfo In dir.GetFiles() Console.WriteLine(" " + fi.Name) Next // C# Console.WriteLine("\nFiles:"); foreach (FileInfo fi in dir.GetFiles()) Console.WriteLine(" " + fi.Name);
7. Build and run your application and verify that you can list volumes, folders, and files.
Exercise 2: Respond to File System Changes
In this exercise, you create a Console application that lists changes to the file system. 1. Using Visual Studio, create a new Console Application project. Name the project WatchFileSystem. 2. Add the System.IO namespace. 3. First, write code to create an instance of FileSystemWatcher as follows:
' VB Dim fsw As New _ FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE")) // C# FileSystemWatcher fsw = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
4. Next, configure the properties of your FileSystemWatcher instance to include subdirectories and notify you only if a file is renamed or updated as follows:
' VB fsw.IncludeSubdirectories = True fsw.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.LastWrite // C# fsw.IncludeSubdirectories = true; fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
5. Add a method to handle the FileSystemWatcher.Changed event and that writes the type of change and the path of the changed file to the console as follows:
' VB Sub fsw_Changed(ByVal sender As Object, ByVal e As FileSystemEventArgs) Console.WriteLine(e.ChangeType.ToString + ": " + e.FullPath) End Sub
2
Input/Output
// C# static void fsw_Changed(object sender, FileSystemEventArgs e) { Console.WriteLine(e.ChangeType + ": " + e.FullPath); }
6. Add a method to handle the FileSystemWatcher.Renamed event and write the type of change and the path of the renamed file before and after the change to the console as follows:
' VB Sub fsw_Renamed(ByVal sender As Object, ByVal e As RenamedEventArgs) ' Write the path of a changed file to the console Console.WriteLine(e.ChangeType.ToString + " from " + e.OldFullPath + _ " to " + e.Name) End Sub // C# static void fsw_Renamed(object sender, RenamedEventArgs e) { Console.WriteLine(e.ChangeType + " from " + e.OldFullPath + " to " + e.Name); }
7. Next, in your Main method, add event handlers for each of the four FileSystemWatcher event types as follows:
' VB AddHandler AddHandler AddHandler AddHandler // C# fsw.Changed fsw.Created fsw.Deleted fsw.Renamed fsw.Changed, fsw.Created, fsw.Deleted, fsw.Renamed, AddressOf AddressOf AddressOf AddressOf fsw_Changed fsw_Changed fsw_Changed fsw_Renamed
+= += += +=
new new new new
FileSystemEventHandler(fsw_Changed); FileSystemEventHandler(fsw_Changed); FileSystemEventHandler(fsw_Changed); RenamedEventHandler(fsw_Renamed);
8. Finally, set the FileSystemWatcher.EnableRaisingEvents property to true and wait for user input before terminating the program as follows:
' VB fsw.EnableRaisingEvents = True ' Wait for user input before ending Console.WriteLine("Press a key to end the program.") Console.ReadKey() // C# fsw.EnableRaisingEvents = true; Console.WriteLine("Press a key to end the program."); Console.ReadKey();
Copyright © OnBarcode.com . All rights reserved.