Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple "virtual file" class for .NET (c# if source is available)? [closed]

Tags:

For a long time, I've been looking for a class in .NET that has functionality that makes it so that the operating system thinks there is a file (or directory, or both, etc) at a particular location - but all hooks are passed to a function (or event?) in code.

Example:

If I browse to "x:\fake_directory\" I will see a file there, "fake_file.txt". If I double click on the file, Notepad.exe will launch and the file contents would say "Hello World". "Hello World" would come from my c# code.

Example of what I hope the class can do (maybe this will explain it better):

VirtualFile.Register("c:\my_file.txt",     delegate { return Encoding.Ascii.GetBytes("Hello World"); }); 

That's, of course, a simplified version of what I'm looking for... but hopefully you get the idea.

The reason why this is 100% needed is to work with legacy code or proprietary (and very old legacy garbage) systems that require reading and writing to the file system to communicate.

like image 869
Timothy Khouri Avatar asked Feb 14 '11 05:02

Timothy Khouri


People also ask

What are files and stream in C#?

A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream. The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream.

What is System IO file?

File Class (System.IO)Provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.


1 Answers

I believe Dokan would fit your needs for a virtual file system library. Dokan is written in c++ but there is a .NET library to interact.

Dokan link

On the other hand, i believe IPC would be better to achieve the needed functionality for which you gave an example in the comments.

like image 191
Simon Smeets Avatar answered Oct 05 '22 02:10

Simon Smeets