简体   繁体   中英

where to place the texfile

I am creating a .net website in visual studio.

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";

so that i can access the file after publishing the site using 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

 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.

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.

Use the 'App_Data' folder in your solution.

If you really want to store your data on the desktop, use the Environment.SpecialFolder enumeration to get the dynamic path. 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

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