English 中文(简体)
MVC3 程序: 用于保存服务器文件的文件夹是什么?
原标题:MVC3 application: What folder to use for saving files on the server?

我有一个 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:inetpubwwwrootMyApplicationApp_DataLogCourseApp-0385JoeBloggs-634734549879496695.xml . 

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path  C:inetpubwwwrootMyApplicationApp_DataLogCourseApp-0385JoeBloggs-634734549879496695.xml .

为什么没有那个文件夹呢?保存这些事物的通常地点是什么?

Thanks, David

问题回答

右点击文件夹并在上下文菜单中选择“ 包含到工程/ 解决方案中 ”

确保相应设定文件夹上的权利 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签