System.IO replacement (local + CIFS)

I’ve been using Reinhard’s awesome CIFS library for awhile ( and the only real hangup I’ve had with it is constantly having to detect if the file/directory is local or on the network and then changing what actions I take based on that.

So I created a drop in replacement for Microsoft’s System.IO library. I started with an exact port of System.IO and then added the CIFS support along with a few teaks. Normal FileStreams can be used for local or CIFS file. All Copy/Move/Delete commands for File/Directory work both locally and over the nework.

For example you can call File.Delete(“\sd\file.ext”) or File.Delete(“\\dir\file.ext”). You can also copy between local/network just as you would locally.

If there’s any interest I’ll post it up in CodeShare.


Good luck with that… :wink:


Actually it would be nice to have some callbacks or hook, so you can add additional file handlers to the System.IO classes.
@ GHI: TinyCLR
p.s. Same for Network sockets

1 Like

Happy to throw more in there while I’m at it. Anything in particular you want to see? For example I’ve already added AbsolutePath, the ability to search by pattern in GetFiles/GetDirectories, change the copy/move buffer size, etc.

@ Skewworks - I can remeber one missing Feature in my CIFS lib:
So far it only Supports plain text Password authentification. For the more safe one’s encryption is required, but I could not find the correct functions in the crypto lib. I think CIFS Needs DES (or similar?) but I could only find TrippleDES (or similar?).

@ Reinhard Ostermeier - Hadn’t run into that issue, but I’m just working with my local PC. I do remember there was an issue with adding additional directories under a root or something like that. I patched the up the first day. Otherwise, I’ve never had an issue w/ your library. It’s rock solid and I’ve used it to deploy my tests for over a year now (maybe even 2?).

@ Skewworks - Using Plain Text Password usually works fine. I tested with several different Windows OS and NAS without any issue.
It’s only a security issue, since the Password for the Network share is transmitted as plain text over the Network.

In case anyone is wondering how I invoked non-public, static, extern methods from a separate namespace and program:


		internal static extern uint GetAttributes (string path);


		internal static uint GetAttributes (string path)
			Assembly asm = Assembly.Load("Microsoft.SPOT.IO");
			Type type = asm.GetType("Microsoft.SPOT.IO.NativeIO");
			MethodInfo staticMethodInfo = type.GetMethod("GetAttributes", BindingFlags.NonPublic | BindingFlags.Static);
			return (uint) staticMethodInfo.Invoke(null, new object[] { path });
1 Like

Nope :whistle:

btw. you should cache the MethodInfo objects of all methods you are calling in static fields. Reflection is expencive.
Also, if there are multiple overloads (with different Parameters) of a method, you might get the wrong one. There is an Overload to Type.GetMethod() that allows you to specify the Parameter types (at least in full .NET, not 100% sure for NETMF).

@ Reinhard Ostermeier - Good point on the static methods, I’ll update my code to cache them. As far as overloads these are unmanaged calls with single signatures so no worries on that front. :slight_smile:

The only issue I’ve run into is invoking a method with an out parameter. Everything I’ve found for addressing it requires items that aren’t implemented in NETMF. Luckily there’s only one call that does it and it can be pretty safely ignored. The method in question gets canRead/canWrite/canSeek which I obtain other ways.