1

I have an existing application which: Creates folders and saves files in a users Documents folder. These file paths are cached so they can quickly reopen them at a later time.

The Documents folder is determined by

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

Some users are using OneDrive. When they save the file, OneDrive automatically moves them from Documents to a defined OneDrive folder so the original cached paths are no longer valid.

Is there a way to determine where these might get redirected to so the software can check? Is there a better way to look at redirected paths for C#/.NET?

I am not seeing anything in SpecialFolders and my searches aren't helping.

Kerfluffel
  • 117
  • 9
  • Would it be possible to instead use the AppData directory to store these files? – Tyler McEntee Feb 18 '22 at 19:55
  • 1
    @TylerMcEntee The files aren't application related data; they are files related to field testing, reports, etc. They can actually choose to put them somewhere else, but we default to Documents. OneDrive is controlling a number of their folders but from a code perspective I am not sure how to detect they might have been redirected. Similar to MS Word showing a recent files list...you save your document to a path...when you click a recent path it would open it unless OneDrive auto-moves it. I thought there might be a way to find folder redirects or something. – Kerfluffel Feb 18 '22 at 20:59
  • 1
    Have you tried getting the OneDrive path as a fallback option when attempting to find the files from the cache? There seems to be ways to find different OneDrive paths from environment variables. Example here: [https://stackoverflow.com/questions/26771265/get-onedrive-path-in-windows](https://stackoverflow.com/questions/26771265/get-onedrive-path-in-windows) – Tyler McEntee Feb 22 '22 at 21:27
  • 1
    @TylerMcEntee Thanks. I can't test these at the moment but it seems like these may be useful. I may just let the user define possible redirected folders to check. If anything changes in the future they can define the first half of the path in a setting. – Kerfluffel Feb 23 '22 at 16:05

0 Answers0