File System Access

R

Robert Holmes

I have tried numerous ways to access the local file system from a hand held
using the compact framework.

I have deployed to the emulator, cradled using the tool from within vs, it
shows as connected, syncs and all else. Then I execute code such as:

DirectoryInfo di = new DirectoryInfo(@"\\mypcname\temp");
label.Text = di.GetFiles().Length.ToString();

where temp is a share on the host machine with Full Control given to
Everyone.

When I do that I get a nondescript System.IO.Exception. the additional thing
that I do is that I add the host machine using the Connection Block from the
PnP group's Software Factory tools.

Any thoughts anyone?
 
R

Robert Holmes

Alex,

Thanks for the response. However from what I can tell, for all this to work
requires that I purchase your SDF package. Is that correct?

regards,
Robert
 
G

Guest

Not really. The blog post contains download links for the Network class that
uses one call to the MarshalEx.StringToHGlobalUni from the SDF v1.4 which is
still free.
FWIW SDF v2 binaries are free as well.
 
R

Robert Holmes

Alex,

Great, thanks! However I get a return value of 53, which, as far as I can
tell, is a path not found error. I sent the full network name to my machine
(e.g. \\networkname\machinename). I will have to play with it to see how to
get it to work.

Thanks again!
 
G

Guest

"Keep in mind that since Windows CE does not support drive letters, your
share name will be mapped to the reserved root \Network. So if you named your
share as “REMOTE“, you'll access it as “\Network\REMOTE\somefile.txtâ€
 
R

Robert Holmes

Alex,

Thanks for the heads up, I did notice that from your blog post, but I cannot
get to that point. What I did was to take the download from that post. When
I double clicked the solution file it opened up in VS 2003, so I copied the
file Network.cs from that project into my own VS 2005 project. Further there
was no object named MarshalEx, but I noticed that the Marshal2 class had a
method named StringToHGlobalUni, so I renamed MarshalEx to Marshal, then ran
it. Other than that I made no changes to the code. When I make the call to
MapDrive I send in a unc of \\\\Nas02\\2, which is a valid share on the
network. (What I really want is form the local machine but I figure one step
at a time.) I thought I might need to play with the username and/or
password, but the error 53 tells me that it is not seeing the share on the
network.

Furthermore I am referencing the OpenNETCF file that gets loaded in the
C:\Program Files\OpenNETCF\Smart Device Framework 2.0 folder, and it is
version v2.0.50727.

FWIW When I inspect the NETRESOURCE object that gets sent to the API call
the remote and local names are both integers.
 
G

Guest

A few things. First of all, if you're using SDF v2, it already includes the
Network class in the OpenNETCF.Net namespace. Second, try to connect to your
network share from the File Explorer on your device.
 
R

Robert Holmes

Alex,

I made sure to reference the correct dll, OpenNETCF.Net.dll, and called the
right object and method, the static MapDrive from Network by using the
following code:

machineFolder = @"\\Nas02\2"; // a share on the network

try

{

OCF.Network.MapDrive(IntPtr.Zero, machineFolder, "SPT",
@"mydomain\myusername", @"mypassword");

string downloadFile = @"\\Network\SPT\...";

MessageBox.Show(String.Format("File {0} exists: {1}\r\n", downloadFile,
IO.File.Exists(downloadFile)));

di = new System.IO.DirectoryInfo(@"\Network\SPT");

}

catch (Exception ex)

{

System.Diagnostics.Debug.WriteLine(ex.ToString());

}



At the call to MapDrive an exception is thrown, the output of which is as
follows:

A first chance exception of type 'System.ComponentModel.Win32Exception'
occurred in OpenNETCF.Net.dll
System.ComponentModel.Win32Exception: 53
at OpenNETCF.Net.Network.MapDrive()
at DeviceApplication1.frmMsg.menuItem2_Click()
at System.Windows.Forms.MenuItem.OnClick()
at System.Windows.Forms.Menu.ProcessMnuProc()
at System.Windows.Forms.Form.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at DeviceApplication1.Program.Main()

Looking in File Explorer I did not see anything beyond 'My Device' listed,
unless I do not know where to look for it.
 
G

Guest

In the File Explorer there's an icon on the toobar the looks like hand
holding a folder. When you tap on it you will get the prompt for the unc. Try
to connect to your share. How're you connecting to the desktop?
 
G

Guest

In the File Explorer there's an icon on the toobar the looks like hand
holding a folder. When you tap on it you will get the prompt for the unc. Try
to connect to your share. How're you connecting to the desktop?
 
R

Robert Holmes

Alex,

Again, thanks for all the time and effort you have put into this, it is
greatly appreciated.

In File Explorer I do not see the hand on the toolbar, I do not even see a
toolbar. I am using a PocketPC image in an emulator, and I am connecting via
ActiveSync. On the menu there is an option that says 'Open Path' and is
expandable. It shows two options, 'New Path' and '\\STP', apprarently the
share I created. When I click '\\STP' I get a message saying 'the network
path was not found.', then when I click another that says either it does not
exist, or else I do not have permissions. Again I am sending
domain\username, and password to the MapDrive method.

Any ideas?

Thanks again.
 
R

Robert Holmes

No, I have not. We are in the process of evaluating our recommended devices
for the product we are developing to support our main application. We expect
to have some units in house in the next few weeks, but not before.
 
R

Robert Holmes

Chris,

I was able to get a hold of an actual device, iPaq hx2495, and have the same
problem, a number 53 error.

I am out of guesses now.
 
A

Alex Yakhnin

What type of connection is that?
Are you able to connect from File Explorer?

-Alex
 
R

Robert Holmes

Alex,

Again, thanks for the time you have expended on this. I am connecting via
the cradle and activesync. However, I am not trying to use activesync to
proces the files, as that only allows syncing with a specific folder based
on the machine and user. I need more control over the file locations and the
ability to move, rename, etc.

- robert
 
A

Alex Yakhnin

I believe you need a real network connection (WiFi, RAS or something like
that) in order for this to work.

Thx... Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top