While implementing XML file reading/writing in my application I saw that when I call XElement.Save(“myfile.xml”) it will overwrite an existing file.
Is this behavior default for all methods that Save files in C#/ASP.NET or does it depend on the permissions given to ASP.NET?
If my app will be deployed by different people on different hosting setups, what factors should I take into consideration for the possible limitations (if any) that can be placed on my app when reading/writing files?
Will a certain server setup only allow me to overwrite existing files when I delete the old one?
When saving files that will be used later by my application, is App_Data the safest folder to save them in?
The default behaviour issue is really a separate beastie from the permissions issue…
There is no single guiding principle for the default behaviour wrt overwriting in .NET Framework methods that save data to files. For any given method that you invoke, you should investigate the default behaviour. If you don’t like it, you can look for a workaround. For example, the XmlDocument.Save method has an overload that accepts a stream instead of a file path. You can use this by providing a FileStream opened using a FileMode other than Create (which is what is used by the XmlDocument.Save(string) overload).
Regardless of the file creation and/or modification approach that a method attempts to use, the file modification attempt will fail (with an exception raised) unless both of the following conditions are met: