1

I have set of files (which are essentially ".exe" files) that I allow the users to download from my website. To have a clearer picture have a look at the this screenshot (it is just a academic project). Now I have administrator privilege in which I can upload a new software file to a folder (componentsFolder) to the root of my website and I also add the filepath to the database table at the same time.

I'm using the following code to do that:

string componentRelativeFilePath = @"/ComponentsFolder/" + ComponentName;

I'm storing the filepath in the following format in the database file: /ComponentsFolder/FileName.exe

What is the difference between storing the files in the following formats?

  1. /ComponentsFolder/FileName.exe
  2. \ComponentsFolder\FileName.exe
  3. ~/ComponentsFolder/FileName.exe
  4. ~\ComponentsFolder\FileName.exe

I'm using server.mappath to retrieve the file from the root folder.

I want to know the difference (in this context) between these formats and which one is the standard/appropriate/technically correct format to store the relative paths in database table.

dbc
  • 80,875
  • 15
  • 141
  • 235
Sree
  • 6,255
  • 19
  • 64
  • 104
  • I think this post will answer your question: http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath – keyboardP May 08 '11 at 18:41
  • @keyboardP i think there is a difference. And i also want to know which one is standard/appropriate/technically correct format to store the relative paths in database table ? – Sree May 08 '11 at 18:46

1 Answers1

1

In terms of Asp.Net lets suppose you set your image path as "/Image/pic1.jpeg" so the image would be searched in Image folder located in website root and in that folder pic1.jpeg is searched. If your set you image source to "~/Image/pic1.jpeg" in that case as well the image file is read from the Image folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located. But '~/' this could only be used with server controls. If path is "../Image/pic1.jpeg", in that case Image folder is searched in the current webpage's folder.

As per my opinion storing path in "~/Image/" format is a better choice in terms of Asp.Net.

Hope I answer your question.

FIre Panda
  • 6,061
  • 2
  • 23
  • 34
  • whats the difference between the forward slash and backward slash in the file format ? And more over can you please tell me which is more appropriate format to store the file path ? – Sree May 08 '11 at 19:02
  • what do u mean by "so the image would be searched in the folder containing the current page" ?? can you please explain me more eloborately ? – Sree May 08 '11 at 19:08
  • Consider this format "/Image/pic1.jpeg", pic1.jpeg is searched in "the folder of your current webpage/Image." Hope you get me now. – FIre Panda May 08 '11 at 19:11
  • I have checked it, what you have suggested in the answer doesn't seem to be the case ? There is no perceptible difference between the two formats, when i debugged for both formats with "~" and with out "~", the full path seems to be the same when i try to get the full path using server.mappath. I don't understand where does your concept comes into play !!! Does server.mappath execution differ from development server to production server ? – Sree May 08 '11 at 19:32