Interacting with the File System in Visual Basic .NET

Painting QR Code ISO/IEC18004 in Visual Basic .NET Interacting with the File System
1143 Interacting with the File System
Creating QR Code 2d Barcode In VB.NET
Using Barcode maker for VS .NET Control to generate, create QR Code image in .NET applications.
In many of the programs you write, you will want to give the user the opportunity to provide a le with a meaningful name, in much the same way as Word, Excel and even Visual Basic do We could simply expect the user to type the fully quali ed le name, such as: c:\ Documents and Settings\ Default User\ My Program\ My Datadat into a TextBox control or an InputBox statement, but this is error prone and is not the Windows way of doing things Where possible, the user should be able to select
Draw Barcode In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create bar code image in Visual Studio .NET applications.
114 File Storage
Quick Response Code Generation In Visual C#.NET
Using Barcode encoder for VS .NET Control to generate, create Quick Response Code image in VS .NET applications.
a le for input, or select a folder to write a le to The SaveFileDialog and OpenFileDialog controls exist to give us this capability with only a small amount of programming Both are available as controls from the WinForms Toolbox in Visual Studio However, both can also be used very easily by writing a few lines of code within an event or a sub on a form For example, the code in Listing 115 will load a le that the user chooses from the le system in response to a click on the File/Open menu
Denso QR Bar Code Encoder In Visual Studio .NET
Using Barcode generator for ASP.NET Control to generate, create QR image in ASP.NET applications.
Private Sub FileOpen() Dim dlgOpen As OpenFileDialog = New OpenFileDialog() dlgOpenFilter = "Text Files|*txt|All Files|**" dlgOpenInitialDirectory = ApplicationExecutablePath If dlgOpenShowDialog = DialogResultOK Then fileName = dlgOpenFileName 'Open and read file here ' End If End Sub Listing 115: Using the FileOpen dialog box
QR Code 2d Barcode Printer In Visual Studio .NET
Using Barcode generator for .NET framework Control to generate, create QR Code image in Visual Studio .NET applications.
In this code, we rst create a new OpenFileDialog object (not necessary if you are using an OpenFileDialog control from the Toolbox), set its lter so that it will show only Text les (with the le extension txt ) or any le ( * ) depending on which the user chooses from the Files Of Type: combo box, and then show it as a dialog box Note the format of the Filter property This is organized as pairs of sub-strings separated by the | character (shift+ \ on my keyboard) The rst substring in a pair is the name of the le type (eg Text les) and the second is a wildcard description of the le type that the operating system will understand We can specify any text le as *txt , meaning a le whose name ends in the extension txt Any le is ** If the user selects a le and presses the OK button we can then retrieve the le-name from the control and go on to open it Note that I ve used a bit of sleazy code in Listing 115, by setting the InitialDirectory property of the OpenDialog control to be ApplicationExecutablePath Strictly speaking, this is the full path to and le-name of the executable program (eg c:\VBNETPrograms\FileDemo\bin\ ledemoexe) and so includes a name for a le However, the OpenDialog control expects only a directory, and will simply ignore the le name part, returning c:\VBNETPrograms\FileDemo\bin\ or whatever folder the program is running from I nd it much easier to store the les belonging to an application in the application s own folder, since if I ever decide to move the program, I can move the folder and the les will come too If you re slavishly following Microsoft s guidelines on where to store data les, the Application property to use in place of ExecutablePath is one of:
Create Barcode In Visual Basic .NET
Using Barcode drawer for VS .NET Control to generate, create barcode image in Visual Studio .NET applications.
ApplicationCommonAppDataPath() ApplicationLocalUserAppDataPath()
Generate Barcode In VB.NET
Using Barcode creator for .NET Control to generate, create bar code image in .NET applications.
11 n Files, Streams and Serialization
Painting Code 39 Extended In VB.NET
Using Barcode creation for VS .NET Control to generate, create USS Code 39 image in .NET framework applications.
both of which will return a folder in the My Documents area of the main disk drive that Windows is installed on Saving a le to a chosen location is very similar to Listing 116
USS Code 128 Encoder In Visual Basic .NET
Using Barcode drawer for .NET Control to generate, create Code 128B image in Visual Studio .NET applications.
Private Sub FileSaveAs() Dim dlgSaveAs As SaveFileDialog = New SaveFileDialog() dlgSaveAsFilter = "Text Files|*txt|All Files|**" If dlgSaveAsShowDialog = DialogResultOK Then fileName = dlgSaveAsFileName 'Open and save the file FileSave() End If End Sub Listing 116: Using the SaveFileDialog dialog box
Print Data Matrix ECC200 In VB.NET
Using Barcode encoder for .NET framework Control to generate, create Data Matrix image in .NET applications.
Note that in a program that allows the user to choose the name to save a le as, there are normally two menu options for saving, as shown in Figure 112
Code-128 Drawer In VS .NET
Using Barcode generation for ASP.NET Control to generate, create Code-128 image in ASP.NET applications.
Barcode Generation In C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
EAN-13 Supplement 5 Creation In Java
Using Barcode drawer for Java Control to generate, create UPC - 13 image in Java applications.
Generate UCC-128 In .NET Framework
Using Barcode encoder for .NET Control to generate, create EAN / UCC - 13 image in VS .NET applications.
Bar Code Encoder In Visual Studio .NET
Using Barcode creator for .NET Control to generate, create barcode image in VS .NET applications.
UPCA Drawer In Java
Using Barcode creation for Java Control to generate, create UPC A image in Java applications.