将数据写入App_Data [英] Writing data to App_Data
问题描述
我想用下面的代码写一个.xml文件到App_Data / posts。为什么会导致一个错误?
$ b $ h3 Code $ h
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $流$ $ $ $ $ $ $流$ $新的FileStream(..'\'App_Data'\'posts'\'+ new Guid(post_ID.ToString())。ToString()+.xml,FileMode.Create);
不只是它不工作 - 这可能是各种各样的问题。这里有几件事要检查:
检查ASP.NET进程是否有写访问权限
<另外,看起来你正在逃避路径中的退格错误。在使用ASP.NET时,您的路径应该与应用程序根目录相关。试试这个:
pre code> string path = HttpContext.Current.Server.MapPath(〜/ App_Data / posts /+ new Guid ();
$ p $>
最后,确保posts目录存在 - 否则文件创建将失败。
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);
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.
这篇关于将数据写入App_Data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!