How do you read a data file located on PC from the emulator Or how do you save a data file on the emulator from the PC
Thanks,
Pete_M
How do you read a data file located on PC from the emulator Or how do you save a data file on the emulator from the PC
Thanks,
Pete_M
Read data file located on PC from emulator?
Keyrus
You have couple options:
1. You can access network drives on PC from emulator or device by specifying path as follows: "\\host\share\path\file". That would work for Pocket PC, but not SmartPhone as it has no support for that. You can try it from File Explorer on device/emulator.
2. You can map any folder on the desktop or network on to emulator's flash card if you're using new emulator from VS 2005. That is done via emulator's menu: File\Configure\General\SharedFolder.
To save file from device to emulator/device you can cradle it and use RAPI (from Remote API). OpenNetcf.org has easy to use managed wrapper for that.
Or, you can add this file to your VS project and set action to “content”. VS would deploy file for you.
Jester
Thanks for your help Ilya.
Pete M
KennyKls
Can you give an example of the first option.
I've tried to do the second option:
2. You can map any folder on the desktop or network on to emulator's flash card if you're using new emulator from VS 2005. That is done via emulator's menu: File\Configure\General\SharedFolder.
and when i type a command to read the file:
StreamReader sr = new StreamReader("TestFile.txt");
I get an error that the program can't find the file on the emulator. Can you provide me a sample read command that has the path of the file on the emulator (or shared folder) written out.
Thanks!
Peter
Youssef
Example of the first option would be:
StreamReader sr = new StreamReader(@"\\server\share\path\TestFile.txt");
You can verify if path is correct by typing it in Start/Run on the desktop. Note I’m using @ so I won’t have to escape \ character. If you don’t like that, you’d need to double slashes. Note you might be prompted for credentials.
Device does not support relative paths, so whatever path you specify is absolute starting from root. Let's take a look at your code:
StreamReader sr = new StreamReader("TestFile.txt");
In this case it device would try to open file “TestFile.txt” located in the root folder of the device. Since it's in fact located on simulated storage card which in turn located in root, it won't be found in the root.
To make it work please specify full path:
StreamReader sr = new StreamReader(@"\StorageCardNameHare\PathInMappedFolder\TestFile.txt");
I'm not sure what's the emulated storage card name is, you can easily verify with File Explorer. You can also verify access to network share from it.