I’m working on an app that needs to save files in user-chosen folders. The problem is when Controlled Folder Access (CFA) is turned on. If a user tries to save in a CFA-protected folder, like Documents, the app gets blocked. The error message is confusing, saying the file wasn’t found.
I know how to check for CFA at startup, but I can’t figure out how to do it in the SaveFileDialog. Once you close the ‘file not found’ message, you’re out of the dialog without knowing which folder caused the issue.
Is there a way to detect when a user selects a CFA-protected folder in SaveFileDialog? I want to show a helpful message explaining what’s happening and how to fix it. I don’t want to force users to allow the app by default, as not everyone has CFA enabled.
Any ideas on how to make this work? It seems like a common problem, but I can’t find a good solution.
Hey there, Liam39! Wow, that Controlled Folder Access can be such a pain, right? I’ve run into similar issues before, and it’s super frustrating when you’re just trying to save a file!
Have you thought about trying to catch the exception after the SaveFileDialog closes? You could attempt a quick write test to the selected folder and see if it fails. If it does, that might be your clue that CFA is causing trouble.
Oh, and here’s a wild idea - what if you created a little helper app that checks folder permissions? You could run it before opening the SaveFileDialog to give users a heads-up about potential CFA issues.
I’m really curious - have you considered using a custom file picker instead of SaveFileDialog? It might give you more control over the whole process. What do you think about that approach?
And hey, while we’re brainstorming, how about adding a “Test Save Location” button in your app? Users could check if a folder is writable before they even try to save. Could be a nifty feature!
Keep us posted on what you end up doing! I’d love to hear how you solve this. Good luck!
I’ve dealt with similar CFA issues before, and it’s definitely tricky. One approach that’s worked for me is implementing a post-dialog check. After the SaveFileDialog closes, try writing a small temporary file to the selected location. If it fails, you can reasonably assume it’s due to CFA and display a tailored message to the user.
Something like:
try {
File.WriteAllText(Path.Combine(selectedPath, “test.tmp”), “test”);
File.Delete(Path.Combine(selectedPath, “test.tmp”));
} catch (UnauthorizedAccessException) {
MessageBox.Show(“This folder appears to be protected by Controlled Folder Access. Please add our app to the allowed list in Windows Security settings.”);
}
This method isn’t perfect, but it provides a more user-friendly experience than the default error. You could also consider adding a help section in your app explaining CFA and how to modify its settings for users who encounter this issue frequently.
hey liam39, that cfa stuff is a real headache! have u tried catching the exception after the dialog closes? maybe do a quick write test to see if it fails. could give u a clue about cfa problems.
or what about making a lil helper app to check folder permissions before opening savedialog? might save some hassle. just some ideas to play with. good luck!