Sreedhar Danturthi
Sreedhar Danturthi

Reputation: 7571

Options for storing file path of the component in database

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.

Upvotes: 1

Views: 1157

Answers (1)

FIre Panda
FIre Panda

Reputation: 6637

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.

Upvotes: 1

Related Questions