我有一个应用程序MVC3应用程序。我想记录各种事情,比如提交表单特定表单时,为了避免写入数据库,我想在xml文件中记录详细信息。
问题是我应该使用哪个文件夹,我见过的一些示例建议使用App_Data文件夹。对于最少的问题,什么是常态或建议?
所以我用这个:
// Create a new XmlSerializer instance with the type of the test class
var serializerObj = new XmlSerializer(typeof(CourseApplicationVM));
// Create a new file stream to write the serialized object to a file
var filename = string.Format("{0}-{1}-{2}{3}", "CourseApp",
viewModel.Course.Code + viewModel.Applicant.Name, DateTime.Now.Ticks, ".xml");
var filepath = Path.Combine(Server.MapPath("~/App_Data/Log"), filename);
TextWriter writeFileStream = new StreamWriter(filepath);
serializerObj.Serialize(writeFileStream, viewModel);
// Cleanup
writeFileStream.Close();
它在本地工作正常,但在发布到服务器时却没有。在查看文件夹结构时,这并不奇怪,因为它在发布时甚至没有App_Data文件夹。这导致了这个错误:
Could not find a part of the path 'C:\inetpub\wwwroot\MyApplication\App_Data\Log\CourseApp-0385JoeBloggs-634734549879496695.xml'.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\wwwroot\MyApplication\App_Data\Log\CourseApp-0385JoeBloggs-634734549879496695.xml'.
为什么没有该文件夹(不应该发布)?保存这些东西的正常位置是什么?
谢谢, 大卫
答案 0 :(得分:1)
右键单击文件夹,然后在上下文菜单中选择"包括在项目/解决方案"
确保您对文件夹的权限已相应设置。