How to delete file from relative path in asp.net

622 views Asked by At

My Debugging screenshot

enter image description here

I am trying to delete a file in asp.net web 4.7.1. I'm using FileInfo and checking if file exists using a relative path the points to the Uploads folder and image full name and extension. I have saving the image path in my database and I know if I use full path I will delete the file. How can I delete using the saved path?

I am thinking of modifying my database for each Image to store full path and relative path. I will use the full path for deleting file only. How can I delete without having to create a second database field for storing a full path?

1

There are 1 answers

0
Rahul Neekhra On

One of the best ways to solve such problem (So that application wouldn't face any challenge of path access or read\write access on windows drive level).

Create virtual director and use that virtual directory to save relative path. Set up all access on virtual directory which is one time task.

Then you can use that virtual directory relative path in your code instead of full path.