简体   繁体   English

在哪里放置texfile

[英]where to place the texfile

I am creating a .net website in visual studio. 我正在Visual Studio中创建一个.net网站。

The website makes use of the reading and writing of the text files, my question is where to place my text files, what is the physical path that to be given to access the file. 该网站利用了文本文件的读写功能,我的问题是放置文本文件的位置,访问文件的物理路径是什么。

In my project i access the file using the following statement using 在我的项目中,我使用以下语句访问文件:

var sr = new StreamReader(@"C:\Users\Vinu\Desktop\token.txt");

i want to know that what should be the path of the file instead of @"C:\\Users\\Vinu\\Desktop\\token.txt"; 我想知道文件的路径应该是什么,而不是@"C:\\Users\\Vinu\\Desktop\\token.txt";

so that i can access the file after publishing the site using IIS7. 这样我就可以在使用IIS7发布站点之后访问文件。

To answer your question, it depends on the volume of the file, if the volume of the file is huge and you want to put it in a seperate file server and access it. 要回答您的问题,它取决于文件的容量,如果文件的容量很大,并且您想将其放在单独的文件服务器中并进行访问。 you would be placing that in a share location \\\\sharelocation and access else you can put it in your application directory itself and access the path with 您将其放置在共享位置\\\\sharelocation并访问,否则您可以将其放置在应用程序目录中并使用以下命令访问路径

 Server.Mappath(".")

which will give you the physical path of your root, for the first option of having it in a share location, you can have a variable in your web.config under appsettings which will give you the share location. 这将为您提供根的物理路径,对于将其放置在共享位置的第一种选择,您可以在web.config中的appsettings下有一个变量,该变量将为您提供共享位置。

the reason why i dont propose having it in App_Data is because if you are in an Network load balancer your app_data folder is specific to one instance of your web application, i prefer placing the file in a shared location and accessing them. 我不建议在App_Data中使用它的原因是,如果您在网络负载平衡器中,则app_data文件夹特定于Web应用程序的一个实例,我更喜欢将文件放在共享位置并访问它们。

Use the 'App_Data' folder in your solution. 在您的解决方案中使用“ App_Data”文件夹。

If you really want to store your data on the desktop, use the Environment.SpecialFolder enumeration to get the dynamic path. 如果您确实想将数据存储在桌面上,请使用Environment.SpecialFolder枚举获取动态路径。 eg 例如

Environment.GetFolderPath( Environment.SpecialFolder.Desktop));

NB: The Environment.SpecialFolder enumeration contains other locations like MyDocuments, ProgramFiles etc, see more here: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx 注意: Environment.SpecialFolder枚举包含MyDocuments,ProgramFiles等其他位置,请参见此处的更多信息: http : //msdn.microsoft.com/zh-cn/library/system.environment.specialfolder.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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