locked
Process.Start do not find the correct path RRS feed

  • Question

  • Hi,

    I'm using the desktop bridge, so my Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns something like 

    C:\Users\Kriz\AppData\Local\Packages\48889JohnDoe.myApp_v1dvn23bknv3r\LocalCache\Roaming\myApp

    Saving, opening and editing files with this path is no problem. But when I try to open a pdf file with Process.Start(filepath) I got a error that the file is not there... but I saved it with the same path before that...

    Whats wrong?

    Thank you!

    Kriz

    Wednesday, August 1, 2018 8:15 PM

All replies

  • Hi,

    Have you checked the file in the local folder after saving? Another thing is that does the file is in correctly format? 

    I checked the document about Process.Start() method, it shows the explains the FileNotFoundException as The PATH environment variable has a string containing quotes. Is that the full path of your file? 

    Best regards,

    Roy


    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, August 2, 2018 2:25 AM
  • Hi Roy,

    1. The file is there and works after saving

    2. Opening the file via doubleclicks works fine, so there is no problem with the file

    3. The path has no quotes

    4. Yes, thats the full path

    I've tested something... when I use the Process.Start() method with Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), it do not work, but if I use the Process.Start() method with the full path (C:\Users\Kriz\AppData\Local\Packages\48889JohnDoe.myApp_v1dvn23bknv3r\LocalCache\Roaming\myApp\file.pdf) its working.

    So it seems that the Process.Start() method is looking in the wrong folder. How do I get this method using the same folder like the rest of my app when using Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)?

    Thursday, August 2, 2018 3:18 AM
  • Hi,

    The problem might be related to the different file system policy mentioned here:https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-prepare

    I'm investigating this with other engineers. There might be some time delay.

    Best regards,

    Roy


    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.

    Monday, August 6, 2018 8:09 AM

  • Hi Chris,

    Roy asked me to jump in here and see if I can help. We are a bit confused and just would like to get some clarification.
    You said that if you do this:

    Process.Start("C:\Users\Kriz\AppData\Local\Packages\48889JohnDoe.myApp_v1dvn23bknv3r\LocalCache\Roaming\myApp\file.pdf");

    it works

    If you do this:

    String s = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

    s += "\file.pdf";

    Process.Start(s);

    It does not work. Is this correct? 

    If you can reply with a code expressing exactly what it is that you are doing I think that might be helpful.

    Thanks,

    James



    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 8, 2018 1:11 AM
  • Hi James,

    yes, exactly!

    This is my code:

    pdf.Save(Const.tmpFilePath());
    Process.Start(Const.tmpFilePath());

    and this is a part of my Const-class:

    public static string tmpFilePath()        
    {            
         return ApplicationFolder() + "\\temp.pdf";        
    }                
    
    public static string ApplicationFolder()        
    {            
         return path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "myApp");        
    }

    I am using pdfSharp to generate and save the pdf file. So when I save the pdf, it's saved in the C:\Users\Kriz\AppData\Local\Packages\48889JohnDoe.myApp_v1dvn23bknv3r\LocalCache\Roaming\myApp Folder.

    But Process.Start() is looking in the C:\User\JohnDoe\AppData\Roaming\myApp Folder.

    Chris


    Wednesday, August 15, 2018 4:34 AM
  • Is there any new informaton?

    At the moment I use Environment.SpecialFolder.MyDocuments for my pdf file and thats working. But I want to keep all my data together in the appfolder...

    Chris

    Wednesday, August 22, 2018 2:52 AM
  • As Roy said, this scenario is called out in https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-prepare :

    Your app writes to the AppData folder or to the registry with the intention of sharing data with another app. After conversion, AppData is redirected to the local app data store, which is a private store for each UWP app.
    All entries that your app writes to the HKEY_LOCAL_MACHINE registry hive are redirected to an isolated binary file and any entries that your app writes to the HKEY_CURRENT_USER registry hive are placed into a private per-user, per-app location. For more details about file and registry redirection, see Behind the scenes of the Desktop Bridge.
    Use a different means of inter-process data sharing. For more info, see Store and retrieve settings and other app data.

    Making a few guesses on details of your actual symptom, I suspect that Environment.SpecialFolder.ApplicationData is returning C:\User\JohnDoe\AppData\Roaming\myApp.

    In the UWP context that gets redirected to the Packages data folder and so saves in C:\Users\Kriz\AppData\Local\Packages\48889JohnDoe.myApp_v1dvn23bknv3r\LocalCache\Roaming\myApp .

    Outside of the UWP context--in the context of the app launched by Process.Start--this doesn't get redirected and so the other app looks in C:\User\JohnDoe\AppData\Roaming\myApp and doesn't find the file.

    You can probably switch to Windows.Storage.ApplicationData.Current.RoamingFolder instead of Environment.SpecialFolder to get the non-redirected folder and the path will be the same in both contexts.


    Wednesday, August 22, 2018 4:54 AM