问题描述
在C#中设置我的文本文件的最佳位置在哪里打开它?
Where is the best place to set up my Text File in C# with goal to open it?
推荐答案
using (TextReader tr = new StreamReader(@"C:\Temp\Test.txt"))
{
// Do your file operations
}
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
..它会将ApplicationData文件夹返回给您,如果您将项目托管在服务器上(Web应用程序;在这种情况下,它是App_Data),它也是一种很好的方法。
您可以从任何位置的任何文件中提取数据,因此,最好的方法是将其存储在某处。不要以为用户将无法从他的系统中删除此文件。他仍然可以删除,但在ApplicationData文件夹中,较少的用户可以使用你的文件。
..it would return the ApplicationData folder to you, it is also a good approach if you're having your project hosted on a server (a web application; in this case, it is App_Data).
You can extract data from any file at any location, so, the best method is to just store it somewhere. Don't think user won't be able to delete this file from his system. He can still delete, but inside the ApplicationData folder, less users go to play around with your files.
这篇关于在哪里设置文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!