[英]How to create a resource (text file) from c# code? Or can we edit an existing resource file?
I have built a web application with vacations period planning (didactic purpose). 我已经构建了一个带有休假期计划(教学目的)的Web应用程序。
I need to import a text file with bank holidays once a year (the file will be uploaded in UI). 我每年需要导入一个带有银行假期的文本文件(该文件将在用户界面中上传)。 (ex:
localPath/BankHolidays.txt
- contains: 1.01.2015,31.12.2015,...
). (例如:
localPath/BankHolidays.txt
包含: 1.01.2015,31.12.2015,...
)。
I thought it would be a good approach to save the given text file as a Resource file instead of saving it somewhere else (in ProjectDir) as a normal .txt
file. 我认为这将是一个很好的方法来保存给定文本文件作为资源文件,而不是别的地方保存它(在PROJECTDIR)作为一个正常
.txt
文件。 Because I need to access this file quite often and I don't think it's necessary to save this information in a db... 因为我需要经常访问此文件,所以我认为不必将此信息保存在数据库中...
Is this a really good approach in my case? 就我而言,这真的是一个很好的方法吗?
If it is, how can I save a file in Resources dynamically from my code? 如果是的话,如何从代码动态地在Resources中保存文件?
Have a look at the resourceWriter class on the MSDN: 看一下MSDN上的resourceWriter类:
http://msdn.microsoft.com/en-us/library/system.resources.resourcewriter.aspx http://msdn.microsoft.com/en-us/library/system.resources.resourcewriter.aspx
This class will perform all of the heavy lifting in terms of file I/O and data formatting. 此类将在文件I / O和数据格式方面执行所有繁重的工作。 There is also a great tutorial on how to actually use it at:
关于如何实际使用它,还有很棒的教程:
http://www.c-sharpcorner.com/UploadFile/yougerthen/105232008045338AM/1.aspx http://www.c-sharpcorner.com/UploadFile/yougerthen/105232008045338AM/1.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.