Is it reasonable to assume the user has a My Documents folder?  
Author Message
Andrew_Webb





PostPosted: Architecture General, Is it reasonable to assume the user has a My Documents folder? Top

Our app is running into trouble because the user simply doesn't have a My Documents folder. It doesn't exist in the classic location, and it isn't redirected to anywhere else. So the call to System.Environment.GetFolderPath returns an empty string which our code (so far) doesn't expect. This leads our code to create relative and not fully-qualified file and folder pathnames.

Like Visual Studio, we offer subfolders of the user's My Documents folder as the default locations for the storage of files. Is it wrong to expect that the current logged-in user has a My Documents folder



Architecture4  
 
 
kregger





PostPosted: Architecture General, Is it reasonable to assume the user has a My Documents folder? Top

No, it is not reasonable to assume ANYTHING about a user's computer.

Your code must handle the possibility that GetFolderPath returns an empty string. At install you could check and create a folder for your application, storing the folder path into the registry as an override to My Documents. But you must also check at application startup because the user may have deleted the My Documents folder since the time that the app was installed.

One thing I've learned in many years of leading development teams is that "That'll never happen" is the worst thing you ever want to hear a developer say when defending code that doesn't gracefully handle "corner cases" such as this. "That'll never happen" someday will happen.