2

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?

File Upload ASP.NET MVC 3.0

Community
  • 1
  • 1
Diego_DX
  • 1,051
  • 1
  • 20
  • 33

2 Answers2

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
  • 1
    lol, 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