Vyoms OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Bookmark and Share Rss Feeds

Utilize the Full Functionality of the Whidbey File Management | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Sponsored Ads
Hot Jobs
Fresher Jobs
Experienced Jobs
Government Jobs
Walkin Jobs
Placement Section
Company Profiles
Interview Questions
Placement Papers
Resources @ VYOMS
Companies In India
Consultants In India
Colleges In India
Exams In India
Latest Results
Notifications In India
Call Centers In India
Training Institutes In India
Job Communities In India
Courses In India
Jobs by Keyskills
Jobs by Functional Areas
Learn @ VYOMS
GATE Preparation
GRE Preparation
GMAT Preparation
IAS Preparation
SAP Preparation
Testing Preparation
MBA Preparation
News @ VYOMS
Freshers News
Job Articles
Latest News
India News Network
Interview Ebook
Get 30,000+ Interview Questions & Answers in an eBook.
Interview Success Kit - Get Success in Job Interviews
  • 30,000+ Interview Questions
  • Most Questions Answered
  • 5 FREE Bonuses
  • Free Upgrades

VYOMS TOP EMPLOYERS

Wipro Technologies
Tata Consultancy Services
Accenture
IBM
Satyam
Genpact
Cognizant Technologies

Home » Articles » Utilize the Full Functionality of the Whidbey File Management

Utilize the Full Functionality of the Whidbey File Management








Article Posted On Date : Thursday, March 22, 2012


Utilize the Full Functionality of the Whidbey File Management
Advertisements

This article is based on a pre-release version of Microsoft Visual Studio 2005, formerly code-named “Whidbey.” All information contained herein is subject to change.

This article discusses:

    File System Management and its uses
    File Permissions
    File modes, File Access, File Shares

File Management in Whidbey/VB.NET the beating heart of the technologies that comprise Windows Forms. This article explains various file management operations such as read or write, retrieving properties or setting the properties or copy or move a file using the Whidbey/Visual Studio.NET environment. I hope this will helpful to understand the operation of managing a file.

System.IO.namespace

The input/output operation of file management is handled by the classes in the System.IO.namespace. The System.IO.namespace supports the following activities:

    Reading and writing to binary files, text files etc.
    Reading and writing to data streams
    Basic file support
    Directory support
    Memory streams
    Network streams

You have to include this namespace to your project.

Classes that supports System.IO.namespace

The following classes will support System.IO.namespace in VB.NET.

1. The class Binary Reader used for Reads primitive data types as binary values. Primitive data types are those that are not defined in terms of other data types. Because primitive data types are the basis for all other types, they cannot have element content or attributes. Examples of primitive data types are string, float, decimal, anyURI, and QName.

Usage:

Dim objBinReader as New BinaryReader(File.Open _ ("C:mysamplefile.txt", FileMode.Open))

2. The class BinaryWriter used for writes primitive data types as binary values to a stream.

Usage:

Dim objBinWriter as New BinaryWriter(File.Open _ ("C:mysamplefile.txt", FileMode.Create))

3. The class BufferedStream used for buffering to another stream for read and write operations.

Usage:

' Create an NetworkStream object "objNetStream" that owns clientSocket
Dim objNetStream As New NetworkStream(ClientSocket, True)
' Create an BufferedStream object
' "objBufStream" on top of the NetworkStream
Dim objBufStream as New _ BufferedStream(objNetStream, _ intStreamBufferSize)

Note: The NetworkStream class provides methods for sending and receiving data over Stream sockets in blocking mode

4. The class Directory used for creating, copying, moving, deleting and renaming directories and sub directories. The Directory class includes the System.IO namespace.

Some of the public methods used for Directory class is described as follows.

    CreateDirectory - Creates a new directory in a specified path.
    Delete - Delete the directory from the specified path
    Exists - Checks whether the associated directories exists in the specific path.
    GetCreationTime - Get the creation time of directory
    GetCreationTimeUtc - Get the creation time in universal coordinated time
    GetCurrentDirectory - Get the current working directory of the application
    GetDirectories - Gets the name of subdirectories in the working folder
    GetDirectoryRoot - Get root and volume information for the specified path
    GetFiles - Get or returns all the files listed in the specified directory.
    GetFileSytemEntries - Get or returns all the files and sub directories listed in the specified directory.
    GetLastAccessTime - Last access date and time of the specified directory
    GetLastAccessTimeUtc - Last access date and time of the specified directory in universal coordinator time (UTC) format.
    GetLastWriteTime - Last written date and time of a specified directory.
    GetLastWriteTimeUtc - Last written date and time of a specified directory in universal coordinator time (UTC).
    GetLogicalDrives - Get all the logical drives on the computer.
    GetParent - Get the absolute and relative path of the parent directory.
    Move - Move the specific directory to another location
    SetCreationTime - Sets the creation date and time for the specified directory or file.
    SetCreationTimeUtc - Sets the creation date and time for the specified directory or file in universal coordinated time format.
    SetCurrentDirectory - Sets the current directory to a specified directory in an application path.
    SetLastAccessTime - Sets the last access date and time for the specified directory or file.

Usage:

' Checking whether the directory exists in the specified path
Dim strMyPath As String = "C:mySample"
If Directory.Exists(strMyPath) = True Then
Directory.Delete(strMyPath)
Else
Directory.CreateDirectory(strMyPath)
End If

5. The class DirectoryInfo used the same functionality as Directory class except if you are not going to reuse an object several times.

6. The class DirectoryNotFoundException throws exception error when the file or directory not found in the
specified path.

7. The class EndOfStreamException throws exception error at the past the end of a stream.

8. The class ErrorEventArgs provides data for Error event.

Usage:

' Checking whether the directory exists in the specified path
Dim strMyPath As String = "C:mySample"
' Initializes the "objException" Exception object
Dim objException As New Exception("Cannot create Directory")
' Creates an ErrorEventArgs with the exception.
Dim objErrorEventArgs As New ErrorEventArgs(objException)
If Directory.Exists(strMyPath) = True Then
Directory.Delete(strMyPath)
Else
Directory.CreateDirectory(strMyPath)
End If
' Retrieves Exception from ErrorEventArgs
Dim objReturnedException As Exception = objErrorEventArgs.GetException()
If objReturnedException.Message <> "" Then
MessageBox.Show(objReturnedException.Message
End If
End Sub

9. The class File provides to manage the file manipulation operations such as Creating, Opening, Deleting, Copying and Moving of files using FileStream objects. File class methods are static.

Some of the Public Methods used with File class is as follows:

    AppendText
    Copy
    Create
    CreateText
    Delete
    Exists
    GetAttributes
    GetCreationTime
    GetCreationTimeUtc
    GetLastAccessTime
    GetLastAccessTimeUtc
    GetLastWriteTime
    Move
    Open
    OpenRead
    OpenText
    OpenWrite
    SetAttributes
    SetCreationTime
    SetCreationTimeUtc
    SetLastAccessTime
    SetLastAccessTimeUtc
    SetLastWriteTime
    SetLastWriteTimeUtc

Usage:

' Initializing File class aids in the creation of FileStream objects
Try
Dim strMyPath As String = "C:Benoy emp.txt"
Dim strMyCopyPath As String = _"C:Benoy emp1.txt"
Dim objFS As FileStream = _ File.Create(strMyPath)
' Closing the file
objFS.Close()
' Copy the file
File.Copy(strMyPath,strMyCopyPath
' Delete the file
File.Delete(strMyPath)
Catch
MessageBox.Show("Error in File Operation")
End Try

10. The class FileInfo provides the same file management operation as in File class such as Creating, Opening, Deleting, Copying and Moving of files using FileStream objects, except if you are not reusing the object several times because the security check is not always necessary.

11. The class FileLoadException throws exception error if any error occurs during File Load.

Some of the public methods used with this class are shown below:

    FileName - The associated filename that causes exception.
    FusionLog - Get the log file.
    HelpLink - Help Link association during exception error.
    InnerException - An inner exception that caused the current exception.
    Message - Exception Error Message.
    Source - Error Source.
    StackTrace - The associated string representation of the frames on the call stack.
    TargetSite - The associated method name that causes exception.

12. The FileNotFoundException class throws the exception error when the associated file is not found in the specified path or invalid disk access. The public methods are same as FileLoadException class.

13. The FileStream class supports to read, write, open and close the file management operations as well as it supports to manage the operating system file operations such as pipes, standard input and output.

14. The FileSystemEventArgs class provides data for the directory events as shown below.

    Changed event handler fires the properties or security details such as size, system attributes, last write time, last access time, whenever a file is changed or updated.
    Created event handler fires whenever a directory or file created in a specified path.
    Deleted event handler fires whenever a file or directory is deleted from the specified path.

15. The FileSystemInfo class supports the public methods which you can use for both files and directory in the specified path, which serving as the basis for two objects such as FileInfo and DirectoryInfo, which we understand from above.

16. The FileSystemWatcher class allows to notify or fires any changes occurs in the file system or directory such as a file or directory changed, deleted or created.

The figure 1 shows the NotifyFilter properties, that you can use to watch the notifications.

Figure 1 NotifyFilter Properties


Usage:

' Create a new FileSystemWatcher and its properties
Try
Dim objFileSystemWatcher as New _ FileSystemWatcher()
' Watch the notification for LastAccess and LastWrite, FileName, CrationTime and the renaming of files and directories
objFileSystemWatcher.NotifyFilter = (NotifyFilters.LastWrite Or
NotifyFilters.LastAccess Or
NotifyFilters.FileName Or NotifyFilters.DirectoryName Or NotifyFilters.FileName Or
NotifyFilters.CreationTime)
' Only watch doc files
objFileSystemWatcher.Filter = "*.doc"
' Add event handlers
AddHandler objFileSystemWatcher.Changed, AddressOf OnChanged
AddHandler objFileSystemWatcher.Created, AddressOf OnCreated
AddHandler objFileSystemWatcher.Deleted, AddressOf OnChanged
AddHandler objFileSystemWatcher.Renamed, AddressOf OnChanged
' Begin watching event for changed, deleted, renamed and created
objFileSystemWatcher.EnableRaisingEvents = True
' Define the event handlers.
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Specify what is done when a file is changed, created, or deleted.
MessageBox.Show("File: " & e.FullPath & " " & e.ChangeType)
End Sub
Private Shared Sub OnCreated(ByVal source As Object, ByVal e As RenamedEventArgs)
' Specify what is done when a file is renamed.
MessageBox.Show("File: {0} renamed to {1}", e.OldFullPath, e.FullPath)
Catch
MessageBox.Show("Error in File Operation")
End Try

17. The InternalBufferOverFlowException class throws exception when the buffer overflows during execution of the programs. It supports some of the public methods as shown in the FileLoadException class except FusionLog and FileName, which you saw above.

18. The IOException class throws exception when Input/Output error occurs. . It supports some of the public methods as shown in the FileLoadException class except FusionLog and FileName, which you saw above.

19. The MemoryStream class creates streams that have memory as an array instead of a disk or any storage media. It can reduce the need for temporary buffers and files in an application.

Usage:

Try
' Create a new instance of MemoryStream object
Dim objMemoryStream As New MemoryStream(200)
' Create an instance of UnicodeEncoding
Dim objUnicodeEncoding As New UnicodeEncoding
' Create array of string variables.
Dim strMyText As Byte() = _
objUnicodeEncoding.GetBytes("File Management using Whidbey/VB.NET")
objMemoryStream.Write(strMyText, 0, strMyText.Length)
MessageBox.Show(" _
"Capacity = {0}, " _
"Length = {1}, " _
"Position = {2}", _
objMemoryStream.Capacity.ToString(), _
objMemoryStream.Length.ToString(), _
objMemoryStream.Position.ToString())
Catch
MessageBox.Show("Error in File Operation")
End Try

20. Other class members for this namespaces are

    Path
    PathTooLongException
    RenamedEventArgs
    Stream
    StreamReader class
    StreamWriter
    StringReader
    StringWriter
    TextReader
    TextReader

System.Security.Permissions

The enumeration to get or set file permissions in VB.net is called FileIOPermissionAccess enumerations, which used with the FileIOPermission class. The system namespace used for this enumeration is System.Security.Permissions namespace, which implements IUnrestrictedPermission interface, which defines classes that control access to operations and resources based on permission policy.

Classes that supports System.Security.Permissions

The following classes will support System.Security.Permissions in VB.NET.

    CodeAccessSecurityAttribute
    EnvironmentPermission
    EnvironmentPermissionAttribute
    FileDialogPermission
    FileDialogPermissionAttribute
    FileIOPermission
    FileDialogPermission
    FileIOPermissionAttribute
    IsolatedStorageFilePermission
    IsolatedStorageFilePermissionAttribute
    IsolatedStoragePermission
    IsolatedStoragePermissionAttribute
    PermissionSetAttribute
    PrincipalPermission
    PrincipalPermissionAttribute
    PublishedIdentityPermission
    PublishedIdentityPermissionAttribute
    ReflectionPermission
    ReflectionPermissionAttribute
    RegistryPermission
    RegistryPermissionAttribute
    ResourcePermission
    ResourcePermissionEntry
    SecurityAttribute
    SecurityPermission
    SecurityPermissionAttribute
    SiteIdentityPermission
    SiteIdentityPermissionAttribute
    StrongNameIdentityPermission
    StrongNameIdentityPermissionAttribute
    StrongNamePublicKeyBlob
    UIPermission
    UIPermissionAttribute
    UrlIdentityPermission
    UrlIdentityPermissionAttribute
    ZoneIdentityPermission
    ZoneIdentityPermissionAttribute

Mode, Share and Access of Files

FileMode

FileMode parameter control has the following members:

    Append - Append to an existing file or create a new file if the file not exists
    Create - Create a new file
    Open - Open the file
    OpenCreate - Open a file if exists or it will create a file
    Truncate - Remove all the contents so that its size is zero bytes

Example:

Dim objStreamReader
As New StreamReader("C:enoyMytext.txt")
MessageBox.Show(objStreamReader.ReadToEnd()
objStreamReader.Close()

FileShare

FileShare enumeration allows you to control the share permission to access the FileStreams.

Some of the members included in the FileShare enumerations are Read, ReadWrite, Write, None, Inheritable etc.

Read command allows you to opening the file for reading.
ReadWrite command allows you to opening the file for reading and writing.
Write command allows you to opening the file for writing.

Dim objFileStream As New
FileStream("C:enoyMytext.txt", _
FileMode.OpenOrCreateOpen,
FileAccess.ReadWrite,
FileShare.ReadWrite)

FileAccess

FileAccess enumeration allows you to control the permission to access the FileStreams.

Some of the members included in the FileAccess enumerations are Read, ReadWrite, Write etc.

Conclusion

In this article, we found how to manage windows file operations using different file level operation commands. It allows you to set file permissions, modes, access and sharing of files using VB.NET environment.

    File System Management and its uses
    File Permissions
    File modes, File Access, File Shares






Sponsored Ads



Interview Questions
HR Interview Questions
Testing Interview Questions
SAP Interview Questions
Business Intelligence Interview Questions
Call Center Interview Questions

Databases

Clipper Interview Questions
DBA Interview Questions
Firebird Interview Questions
Hierarchical Interview Questions
Informix Interview Questions
Microsoft Access Interview Questions
MS SqlServer Interview Questions
MYSQL Interview Questions
Network Interview Questions
Object Relational Interview Questions
PL/SQL Interview Questions
PostgreSQL Interview Questions
Progress Interview Questions
Relational Interview Questions
SQL Interview Questions
SQL Server Interview Questions
Stored Procedures Interview Questions
Sybase Interview Questions
Teradata Interview Questions

Microsof Technologies

.Net Database Interview Questions
.Net Deployement Interview Questions
ADO.NET Interview Questions
ADO.NET 2.0 Interview Questions
Architecture Interview Questions
ASP Interview Questions
ASP.NET Interview Questions
ASP.NET 2.0 Interview Questions
C# Interview Questions
Csharp Interview Questions
DataGrid Interview Questions
DotNet Interview Questions
Microsoft Basics Interview Questions
Microsoft.NET Interview Questions
Microsoft.NET 2.0 Interview Questions
Share Point Interview Questions
Silverlight Interview Questions
VB.NET Interview Questions
VC++ Interview Questions
Visual Basic Interview Questions

Java / J2EE

Applet Interview Questions
Core Java Interview Questions
Eclipse Interview Questions
EJB Interview Questions
Hibernate Interview Questions
J2ME Interview Questions
J2SE Interview Questions
Java Interview Questions
Java Beans Interview Questions
Java Patterns Interview Questions
Java Security Interview Questions
Java Swing Interview Questions
JBOSS Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSF Interview Questions
JSP Interview Questions
RMI Interview Questions
Servlet Interview Questions
Socket Programming Interview Questions
Springs Interview Questions
Struts Interview Questions
Web Sphere Interview Questions

Programming Languages

C Interview Questions
C++ Interview Questions
CGI Interview Questions
Delphi Interview Questions
Fortran Interview Questions
ILU Interview Questions
LISP Interview Questions
Pascal Interview Questions
Perl Interview Questions
PHP Interview Questions
Ruby Interview Questions
Signature Interview Questions
UML Interview Questions
VBA Interview Questions
Windows Interview Questions
Mainframe Interview Questions


Copyright © 2001-2024 Vyoms.com. All Rights Reserved. Home | About Us | Advertise With Vyoms.com | Jobs | Contact Us | Feedback | Link to Us | Privacy Policy | Terms & Conditions
Placement Papers | Get Your Free Website | IAS Preparation | C++ Interview Questions | C Interview Questions | Report a Bug | Romantic Shayari | CAT 2024

Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |


Copyright ©2001-2024 Vyoms.com, All Rights Reserved.
Disclaimer: VYOMS.com has taken all reasonable steps to ensure that information on this site is authentic. Applicants are advised to research bonafides of advertisers independently. VYOMS.com shall not have any responsibility in this regard.