Path

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
 
A

Anthony Jones

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top