locked
How to create file from a device emulator? RRS feed

  • Question

  •  

    Hi,

     

    I am writing an instruction manual for a PDA application and that includes the pasting of 

    the  screenshot application images from the emulator to the word document.  The code

    snippet below is a simplification of the concept. 

      

     Private Sub btnCreateTxtFile_Click(ByVal sender As System.Object, ByVal e As

                   System.EventArgs) Handles btnCreateTxtFile.Click

     

            Try
                     Dim srWFile As New System.IO.StreamWriter("\My  

                           Documents\FolderToPutTxtFile\"  &  "mytextfile.txt", False,

                           System.Text.Encoding.Default)     

            Catch exp As Exception
                          MessageBox.Show(exp.ToString())
              End Try     

     

            If file creation is successful Then

                       MessageBox.Show("File Created!")

            Else

                       MessageBox.Show("No File Created!")

            End If

     

    End Sub 

     

    The text file is created in the:

    "\My Documents\FolderToPutTxtFile\" path in the pda if I use the button in the actual

    device.

     

    But no text file is created in the pda path when I clicked the same button from the

    emulator. 

     

     

    Thank you very much in advance.

     

    kareshi - a newbieSmile

     

     

     

    Friday, July 13, 2007 4:48 AM

Answers

  • Hello,

     

        I think, you have mixed emulator and PPC in your reply above.

     

    assuming that the txt file created by running the program from the device is erased before running it from the emulator

     

     

        I did not get this. If I'm not wrong, emulator is one thing, and PPC is another. Emulator emulates a piece of memory in the desktop itself to be a (as though, like it is a seperate) device. So, through emulator, you can't create files in PPC. Emulator has another display which you can see using VS itself.

     

    Thanks

    Udaya.

     

     

    Tuesday, July 17, 2007 5:34 PM
  • Emulator does not see your desktop's hard drive (it has its own isolated and emulated file system) so it does not matter which folder(s) you have on your desktop.

    You must create folder on emulator's file system, not on your desktop's file system whatever it's in "My Documents" or in your project folder.

    So go ahead and some code to create the folder at runtime or create it on emulator’s file system manually using emulator’s file explorer.

     

     

    Wednesday, July 18, 2007 2:57 AM
    Moderator
  • Hi Kareshi,

     

     kareshi wrote:
    Could it  be that the emulator points to a particular path that should have been existing in my local hard drive? I have created "FolderToPutTxtFile" folder in the My Documents folder in my hard drive and I have also created "My Documents\FolderToPutTxtFile\" path in the location of the project file and even in the bin, release and debug folders but the same System.IO.DirectoryNotFoundException : DirectoryNotFoundException pops up when the emulator is used.

     

    Your desktop PC, the Windows Mobile device emulator, and a physical Windows Mobile device are competely different operating environments. If you create a directory in one environment you will not see it within the other.

     

    If you want to create this directory within the device emulator you will need to do it from within the emulator environment itself. One approach is to follow the following procedure:

    • Tap on the start menu within the emulator window
    • Tap "Programs"
    • Within the list of programs select "File Explorer"
    • Use File Explorer to navigate to your folder (My Documents)
    • In a blank spot, tap and hold the mouse/stylus until a popup menu appears
    • Select "New Folder" and type in the name of your new folder

    If you would like to create this Directory programatically as your application runs you could utilise the System.IO.Directory.CreateDirectory method - see MSDN for further details (http://msdn2.microsoft.com/en-us/library/54a0at6s.aspx

    Code Snippet
    Directory
    .CreateDirectory(@"\My Documents\FolderToPutTxtFile");

     

    With the specified path string it is also advisable to use the following method to determine the path to the "My Documents" folder, since this path could be translated into different langauges on Windows Mobile devices designed for other markets:

     

    Code Snippet
    string myDocumentsPath = Environment
    .GetFolderPath(Environment.SpecialFolder.Personal);

     

    Hope this helps,

    Christopher Fairbairn

    Wednesday, July 18, 2007 3:02 AM

All replies

  • Why do you believe it's not created? By any chance, are you looking for the file on desktop file system? That's not going to work as emulator has emulated file system; it’s not using your desktop’s file system directly.

    Does this folder exist on emulator? Also, are you getting an exception? Which one? Stack trace, type, exception message?

    Friday, July 13, 2007 6:18 PM
    Moderator
  •  

    Why do you believe it's not created? By any chance, are you looking for the file on desktop file system?

    No sir. I am looking for the file in the "\My Documents\FolderToPutTxtFile\" path in the ppc

     

    Does this folder exist on emulator? 

    Yes it is. The text file is created in the folder/path above when the program is run from the device but not when run from the emulator(assuming that the txt file created by running the program from the device is erased before running it from the emulator)

     

    Also, are you getting an exception? Which one? Stack trace, type, exception message?

      Yes. System.IO.DirectoryNotFoundException : DirectoryNotFoundException pops up when I used MessageBox.Show(ex.ToString())
    Tuesday, July 17, 2007 2:49 AM
  • Hello,

     

        I think, you have mixed emulator and PPC in your reply above.

     

    assuming that the txt file created by running the program from the device is erased before running it from the emulator

     

     

        I did not get this. If I'm not wrong, emulator is one thing, and PPC is another. Emulator emulates a piece of memory in the desktop itself to be a (as though, like it is a seperate) device. So, through emulator, you can't create files in PPC. Emulator has another display which you can see using VS itself.

     

    Thanks

    Udaya.

     

     

    Tuesday, July 17, 2007 5:34 PM
  • Clearly that means you do not have this folder on the emulator. Make sure to explicitly create it before writing files into it.

    Tuesday, July 17, 2007 5:58 PM
    Moderator
  •  UdayaBG wrote:

    Hello,

     

        I think, you have mixed emulator and PPC in your reply above.

     

    assuming that the txt file created by running the program from the device is erased before running it from the emulator 

     

        I did not get this. If I'm not wrong, emulator is one thing, and PPC is another. Emulator emulates a piece of memory in the desktop itself to be a (as though, like it is a seperate) device. So, through emulator, you can't create files in PPC. Emulator has another display which you can see using VS itself.

     

    Thanks

    Udaya. 

     

    Hi Udaya-san,

     

     "I did not get this"

    The text file is always created in that particular folder in the PPC when the program is run from the device. I manually erase the created file by accessing that ppc folder thru desktop explorer before clicking again the button in the device to avoid the a particular error due to "file already exists". I have expected that the same error will pop up when the emulator is used and if the file is not erased in that ppc folder.

     

    "So, through emulator, you can't create files in PPC"

    Thanks. In my previous applications, I can insert values in the tables of the networked SQL DB server both from the mobile PPC via WiFi and from the emulator in my desktop pc. I thought I can do similar thing like creating file/s in the PPC by running the program from the emulator.

     

     

     

     

    Wednesday, July 18, 2007 2:03 AM
  •  Ilya Tumanov wrote:

    Clearly that means you do not have this folder on the emulator. Make sure to explicitly create it before writing files into it.

     

    Hi sir,

     

    The folder is certainly existing in the device thats why the file is always created when the program is run from the PPC.

     

    But...how to create "this folder on the emulator?".

     

     Could it  be that the emulator points to a particular path that should have been existing in my local hard drive? I have created "FolderToPutTxtFile" folder in the My Documents folder in my hard drive and I have also created "My Documents\FolderToPutTxtFile\" path in the location of the project file and even in the bin, release and debug folders but the same System.IO.DirectoryNotFoundException : DirectoryNotFoundException pops up when the emulator is used.

     

    Thanks,

     

    k

    Wednesday, July 18, 2007 2:32 AM
  • Emulator does not see your desktop's hard drive (it has its own isolated and emulated file system) so it does not matter which folder(s) you have on your desktop.

    You must create folder on emulator's file system, not on your desktop's file system whatever it's in "My Documents" or in your project folder.

    So go ahead and some code to create the folder at runtime or create it on emulator’s file system manually using emulator’s file explorer.

     

     

    Wednesday, July 18, 2007 2:57 AM
    Moderator
  • Hi Kareshi,

     

     kareshi wrote:
    Could it  be that the emulator points to a particular path that should have been existing in my local hard drive? I have created "FolderToPutTxtFile" folder in the My Documents folder in my hard drive and I have also created "My Documents\FolderToPutTxtFile\" path in the location of the project file and even in the bin, release and debug folders but the same System.IO.DirectoryNotFoundException : DirectoryNotFoundException pops up when the emulator is used.

     

    Your desktop PC, the Windows Mobile device emulator, and a physical Windows Mobile device are competely different operating environments. If you create a directory in one environment you will not see it within the other.

     

    If you want to create this directory within the device emulator you will need to do it from within the emulator environment itself. One approach is to follow the following procedure:

    • Tap on the start menu within the emulator window
    • Tap "Programs"
    • Within the list of programs select "File Explorer"
    • Use File Explorer to navigate to your folder (My Documents)
    • In a blank spot, tap and hold the mouse/stylus until a popup menu appears
    • Select "New Folder" and type in the name of your new folder

    If you would like to create this Directory programatically as your application runs you could utilise the System.IO.Directory.CreateDirectory method - see MSDN for further details (http://msdn2.microsoft.com/en-us/library/54a0at6s.aspx

    Code Snippet
    Directory
    .CreateDirectory(@"\My Documents\FolderToPutTxtFile");

     

    With the specified path string it is also advisable to use the following method to determine the path to the "My Documents" folder, since this path could be translated into different langauges on Windows Mobile devices designed for other markets:

     

    Code Snippet
    string myDocumentsPath = Environment
    .GetFolderPath(Environment.SpecialFolder.Personal);

     

    Hope this helps,

    Christopher Fairbairn

    Wednesday, July 18, 2007 3:02 AM
  •  

     

    Thanks a lot guys for the wonderful info!!!

     

    I am learning so much from standing on your shoulders and I promise to give back  useful info/tips someday 

     

       k. 

     

    Wednesday, July 18, 2007 4:01 AM
  •  kareshi wrote:

     

    Does this folder exist on emulator? 

    Yes it is. The text file is created in the folder/path above when the program is run from the device but not when run from the emulator(assuming that the txt file created by running the program from the device is erased before running it from the emulator)

     

     

    Actually it's a NO. Im just confused between the words device and emulator. Im sorry

     

     

     

    Wednesday, July 18, 2007 4:59 AM