.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

File Handling Methods in VB.NET

Posted By:Abhisek Panda       Posted Date: November 14, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  
 

File Handling Methods in VB.NET:-


Various methods of file handling in VB.NET is given below,

1.Kill(File name with path):-

This method deletes the said file/files from the disk. The name of the file to be deleted is passed to this method as string type arguments. Files are simply deleted and not moved to recycle-bin. The use of wild card(* and /) is permitted in this function.

Kill("C:\Files\abc.txt") This will delete the file abc.txt locates in C:\Files\

Kill("C:\Files\*.txt") This will delete all the files with .txt extension from C:\Files\

2.FileDateTime(file name with path):-

This function returns the date and time of creation of the said file. The name of the file to be deleted is passed to this method as string type arguments.

Debug.WriteLine("Date & Time:"&(FileDateTime("C:\Files\abc.txt"))) This may display the the following output in Debug window.
Date & Time: 29/10/2009 09:54:34AM

3.FileLen(file name with path):-

This method returns the size of the specified file in bytes.The name of the file to be deleted is passed to this method as string type arguments.

Debug.WriteLine("Size of file:"&(FileLen("C:\Files\abc.txt"))) This may return the following line in Debug window
Size of file:106

4.MKDir(folder name with path):-

It creates a new folder(s) in the specified location.

MKDir("C:\Files\MyFile") After execution it will create a new folder MyFile.

5.RmDir(folder name with path):-

This method delets the folder specified.
RmDir("C:\Files\MyFile") It will remove the folder MyFolder.

6.Dir(file name with path):-

This method is used to check if the specified file is present or not.

StrCheck = Dir("C:\Files\abc.txt")
If StrCheck = "abc.txt" Then
Debug.WriteLine("File is present")
Else
Debug.WriteLine("File is not present")
EndIf


If the file exists the after execution it will display 'File is present' in debug window.

There are many more methods. I have included the most commonly used methods.
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend