简体   繁体   中英

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).

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,... ).

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. 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?

Have a look at the resourceWriter class on the MSDN:

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. There is also a great tutorial on how to actually use it at:

http://www.c-sharpcorner.com/UploadFile/yougerthen/105232008045338AM/1.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM