在哪里设置文本文件? [英] Where to set up a Text File?

查看:108
本文介绍了在哪里设置文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中设置我的文本文件的最佳位置在哪里打开它?

Where is the best place to set up my Text File in C# with goal to open it?

推荐答案

假设您有一个存储在目录C中的文件:\ Temp命名为Test.txt。

然后你可以使用代码



Let's say you have a file stored in the directory C:\Temp named called Test.txt.
Then you can use the code

using (TextReader tr = new StreamReader(@"C:\Temp\Test.txt"))
{
    // Do your file operations
}


您可以将文件保存在ApplicationData文件夹,然后您可以从中接收数据。这是您可以/必须保存与您的应用程序相关的数据的地方。



You can save the file inside the ApplicationData folder and then you can recieve data from it. That is the place where you can/must save the data relateed to your application.

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.


这篇关于在哪里设置文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆