Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Visual Basic’s File IO Added to .NET Core

Visual Basic’s File IO Added to .NET Core

This item in japanese

Visual Basic has always had its own libraries. Classes in this library generally fell into one of three categories:

  • VB Language support
  • Legacy functions needed by upgraded VB 6 applications
  • Convenience functions

The language support handles things such as dynamic typing (C# has a similar library). These are not meant to be used directly so there’s not much more to say about them. Likewise, the legacy functions are only important to very old applications.

The convenience functions are the topic of this article. This functionality was originally created by the VB team to enable faster application development. For example, say you want to copy a directory. Using normal .NET code, you would have to write a recursive function that walks the directory copying each file and recursively processing subdirectories.

If using VB (or referencing VB’s library from C#), you can simply call FileSystem.CopyDirectory. Not only is this much easier for novices, professionals can save a lot of time by using these abstractions.

Some of these methods even expose OS functionality that is missing from the rest of the .NET library. Say you wanted to send files to the Windows recycle bin when deleting them. Without using the Visual Basic library, you need to write about 150 lines of Win32 p/invoke code. The same is true if you want to display the Windows file operation progress bar.

One could argue that these methods should have been in main .NET libraries. But for whatever reason they were segregated into the Microsoft.VisualBasic library. And since VB was considered low priority, much of it wasn’t included in the initial releases of .NET Core.

With .NET Core 3.0, many of these missing functions are being ported, but not all of them will be cross-platform. Shell operations (e.g. recycle bin, file progress bar) are not available on Linux so those will throw a PlatformNotSupported exception.

Along with the FileIO functionality there is the TextFieldParser. This is an RFC compliant CSV parser that can also handle fixed-width files.

For more information, see the File IO pull request.

Rate this Article