25

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.

Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
  • Not if this is what you're looking for but I think the concepts are the same. I've never used it for the kind of thing you're trying to do however. http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualfile.aspx – Shiv Kumar Feb 14 '11 at 05:41
  • The `VirtualFile` class will not work for the requirements in the question. This class is specifically designed to work with and only consumed by the ASP.NET compilation system. Standard IO libraries are not aware of this type and therefore will not be able to do anything with it. – marcind Feb 14 '11 at 07:07
  • Why not use a the FileSystemWatcher class to track changes on a real file? – BertuPG Feb 14 '11 at 10:04
  • @BertuPG - One scenario that I have had to accommodate in the past is a PCI (Payment Card Industry) issue. No "secure data" was *EVER* allowed to be written to the hard drive in an un-encrypted state. We were not allowed to have it written in clear text by the legacy system and then "quickly encrypt it." – Timothy Khouri Feb 14 '11 at 13:04

2 Answers2

7

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.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Simon Smeets
  • 581
  • 6
  • 17
3

Depending on whether your data is static or generated on the fly, you will find either Callback File System or Solid File System OS Edition suitable for your needs (both are our products). SolFS is a ready to use virtual file system with built-in container. Callback File System is a virtual file system without container (you provide structure and data on the fly).

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • The products there seem very tantalizing... I've BlueScreened with Dokan now abut 30 times during development. Seems that a slight bug in my code results in death. If we like the functionality that this brings for our users, we will likely evaluate your product as well. – Timothy Khouri Feb 18 '11 at 02:53
  • @Timothy Mistakes in callbacks *sometimes* can cause BSOD, but with our products you must be especially unlucky to make such mistake - our user-mode APIs handle most mistakes in user-mode and don't let them crash the system. – Eugene Mayevski 'Callback Feb 18 '11 at 06:45