Path

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am uploading a file. Which one should I use?

FileUploadInsert.SaveAs(Server.MapPath("App_Files/MyFile.jpg"))

or

FileUploadInsert.SaveAs(Server.MapPath("~/App_Files/MyFile.jpg"))

Both work. Is "~/" necessary in this case?

Thanks,
Miguel
 
shapper said:
Hello,

I am uploading a file. Which one should I use?

FileUploadInsert.SaveAs(Server.MapPath("App_Files/MyFile.jpg"))

or

FileUploadInsert.SaveAs(Server.MapPath("~/App_Files/MyFile.jpg"))

Both work. Is "~/" necessary in this case?

Both work because the App_Files folder is found in the applications top
folder and so is this page. If you move this page to a deeper folder but
want the App_Files to remain at in the top folder then the former relative
path will break. OTH, if you were to move both this page ant the App_Files
folder into a deeper folder then the latter absolute path will break

IOW, which one you use depends on how tightly coupled the location of the
page executing the code is to the location of the App_Files folder. If
App_Files is highly unlike to be moved deeper into the folder structure at
somepoint in the future use the latter absolute path.
 
Back
Top