I am learning mvc3 and I wanted to know which will be the better way to upload a file and store to the server hard disk, I know how save in the database and saw this example for store in App_Data, which will be the approach to upload a file and store to the server hard disk?
Asked
Active
Viewed 4,417 times
2
-
App_Data is on the server hard disk. It lives inside the web application path. – jrummell Nov 07 '11 at 17:39
-
so save in the app_data and then copy to the folder that I want? – Diego_DX Nov 07 '11 at 17:55
2 Answers
9
Just call file.SaveAs()
with any path on the server's disk that you have write access to.

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
1lol, sorry for waste your time var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); I have to erase "Server.MapPath()" and put my addres there and work, sorry for the trouble var path = Path.Combine((@"D:\uploadTest"), fileName); – Diego_DX Nov 07 '11 at 18:06
1
There are different opinions about this. You should prefer hard disk storage when performance is important and files are big and database when you need transactional integrity between the files and the associated metadata.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928