locked
File exists problem

    Question

  • I have the following code to determine whether the file exists and return the folder path, i.e. if the target file exists in Windows.ApplicationModel.Package.Current.InstalledLocation folder, it will return the installed location path, if the file exists in ApplicationData.Current.LocalFolder, it will return the appdata path. (The File.Exists function is no longer in .Net ??)

            public static async Task<string> GetDataFolderPath(string filename)
            {
                StorageFolder assets = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
                try
                {
                    var item = await assets.TryGetItemAsync(filename);
                    if (item != null)
                        return assets.Path;
                }
                catch
                {
                }
    
                StorageFolder local = ApplicationData.Current.LocalFolder;
                try
                {
                    var item = await local.TryGetItemAsync(filename);
                    if (item != null)
                        return local.Path;
                }
                catch
                { }
                return null;
            }

    The question is, when I debugging step over the function, the debugging process is stopped without any response, no messages no exceptions.

    But when I debugging step into this function, it could successfully determine the file in which folder and return the exact path.

    Please tell me what is going on.


    Saturday, May 10, 2014 3:33 PM

Answers

  • Hi Anne

    I found another way to solve this problem, that is don't check the file in which folder, just give the function local folder path and let him to access.

    Monday, May 12, 2014 2:04 PM

All replies

  • Hi,

    I create a project and test your code in my computer. I found everything is ok. When I debug the funcation by step over or step into i can get the file path. The image below reflect the result when I debug the funcation by step over:

    I think there is no problem in your code. The problem occurs may because of your VS environment.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 12, 2014 1:56 AM
  • Hi Anne

    I found another way to solve this problem, that is don't check the file in which folder, just give the function local folder path and let him to access.

    Monday, May 12, 2014 2:04 PM