I want to write an .xml file using the following code into the App_Data/posts, why is it causing an error:
Stream writer = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(post_ID.ToString()).ToString() + ".xml", FileMode.Create);
I want to write an .xml file using the following code into the App_Data/posts, why is it causing an error:
Stream writer = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(post_ID.ToString()).ToString() + ".xml", FileMode.Create);
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:
string path = HttpContext.Current.Server.MapPath("~/App_Data/posts/" + new Guid(post_ID.ToString()).ToString() + ".xml"
Stream writer = new FileStream(path, FileMode.Create);
Finally, ensure that the posts directory exists - or the file creation will fail.
Remove the extraneous single quotes and escape your backslashes properly.
Or even better, use Server.MapPath
(available in the Page and UserControl base classes and the HttpContext among other things).
Server.MapPath("~/App_Data/posts/" + new Guid(post_ID.ToString()).ToString() + ".xml")
Out of curiosity, what is the type of post_ID? Why are you converting it into a string, then into a guid, and then back to a string?