Windows Forms, Settings.Settings and Microsoft OneDrive

Tom Blahovici 1 Reputation point
2022-09-29T16:58:12.897+00:00

Hi
I have a Windows forms application that uses Application settings using the .NET settings class.
Typically I have a setting such as WindowXSize which is loaded when the program starts, and saved when it ends as follows:

Properties.Settings.Default.WindowXSize = 400;
Properties.Settings.Default.Save;

On load it is just the reverse.
Now this works fine and I have thousands of users with no issues. However, if someone has configured MicroSoft OneDrive to replicate their documents folder, the values never change even if the window is resized.
Not only that, the software can also allow users to save various files in a folder of their choice. Most of the time this is in the documents folder (or subfolder of it). To make sure I get the correct location of the Documents folder I have the following:

 path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)  

This always returns the typical c:\users\userid\documents folder even if OneDrive is syncing the documents folder. The user can then save the file and there are no errors. However, if the user then tries to load it, the file is not found. So it would seem that OneDrive is completely ignoring the .NET mechanisms for Application settings and file IO.
Is there any work around for this? Or am I doing something wrong?
Note that I refuse to load up OneDrive for my documents on my development machine so as to avoid all these issues as well as many others that exist.
Thanks, Tom

Developer technologies | Windows Forms
Microsoft 365 and Office | OneDrive | For business | Windows
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.