Click here to Skip to main content
15,355,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When we write XML file then XmlWriter exception

System.UnauthorizedAccessException: Access to the path 
'D:\WorldMap\EXnetherlands_data.xml' is denied.
 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)  
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights,Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
Updated 29-Apr-11 1:26am


he problem is that IIS user or NETWORK SERVICE user need to have permissions to write the file to destination folder location. Follow the link below to know how to add permission to that folder.[^]

Hope this will help.
Monjurul Habib 29-Apr-11 14:13pm
nice link. my5.
Check you access permissions to the folder.
give the proper permissions to the folder using security tab from properties window
When you are writing in a file on the server, you need to have appropriate write permission to the account processing the request on the directory that you are using to access the file.

Either provide the write permission to the user (generally ASPNET user) or to the user account that is impersonating the calls.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900