I want to write a .xml file using the following code into the App_Data/posts. Why is it causing an error?
Code
Stream writer = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(post_ID.ToString()).ToString() + ".xml", FileMode.Create);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Please post the exception you are getting; not just “it does not work” – this can be all sorts of problems. Here is a few things to check:
Check whether the ASP.NET process has write access to that directory.
Also, it looks like you are escaping the backspaces in the path wrong. And when working with ASP.NET, your paths should be relative to the application root directory. Try this:
Finally, ensure that the posts directory exists – or the file creation will fail.