简体   繁体   中英

How to define correct path for file in my ASP.NET application

Im trying to save file to D:\folder1\folder2\file.txt code for creating a file but it gives me an error because i have root directory at C:\programfiles(x86)\llsExpress I need a path which will work even when i will deploy application Error of the path

First I'd suggest you to try to store your file in a relative path in the root folder if possible. This helps with security plus you'll know that all the files for your site are in the root folder.

If you really want to store files on a different drive, you cannot use relative paths to do this. So no .. in your paths. You'll have to use the absolute path. Store that somewhere in config or environment variables to avoid configuring file paths hard coded.

Finally please use code blocks to show code rather then screenshots on StackOverflow. You can do this by putting the code as text between these chars ``. like this

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