File Directory in C# RRS feed

  • Question

  • Hi, I am new to c# I want to ask if its possible to enter an external directory using C#, because in my case I have an external device called Windows CE, DOT handheld. .

    Here, I am trying to delete a file in a specific directory, this time I am using the C drive which works fine for me.


    But when I use a different Directory on Computer tree-view where all Drive is listed Like:

    • Local Disk (C:)
    • Files (X:)
    • Cherry (This is an external device connected through cable a Windows CE, DOT handheld)

    This time I will use CHERRY device as a directory and tried this code but didn't work

    File.Delete(@"Computer\CHERRY\\\Program Files\ManPa\maPA.exe");
    Any work-around for this one ? Thanks..

    • Edited by JZoler Wednesday, October 31, 2018 1:48 AM
    Wednesday, October 31, 2018 1:34 AM

All replies

  • The correct UNC path has the form of the following. Please correct it and check again to see if it works.

    \\<computer name>\<share name>\<path>

    Altenatively you can just write a simple program that allows you to select a file through OpenFileDialog and display the path to see it. I'm pretty sure a path starts with "Computer\<computer name>" is not a valid one.

    Wednesday, October 31, 2018 2:01 AM
  • File.Delete(@"C:\folder1\folder2\maPA.exe");

    Here just replace "C:" with "E:" or "X:" or whatever letter your external device gets in explorer

    Wednesday, October 31, 2018 8:12 AM
  • Hi Jreloz,

    Firstly, please check if you have permission to read/write the file in your external device. 

    Then try the following code.

    var uri = new Uri("file://ComputerPCName/folder1/folder2/maPA.exe", UriKind.Absolute);

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 1, 2018 2:11 AM
  • This thread suggest the path could be @"\Program Files\ManPa\maPA.exe", so you may check with the following and see if it works before continues.

    if (File.Exists(@"\Program Files\ManPa\maPA.exe"))
        Console.WriteLine("Not Found!");

    If the folder somehow exist on storage cards like CompactFlash, prepend "\Storage Card" to the path.

    If your PC supports ActiveSync, here's code example for copying file with RAPI P/Invoke.

    EDIT: The first link I quoted also need ActiveSync to work, so RAPI is the only way to try.

    Thursday, November 1, 2018 3:11 AM
  • If you were sitting at a console window on that computer, how would you refer to files on the "Cherry" device?  What path would you type?  You'd use the same path in your code.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Sunday, November 4, 2018 2:21 AM