1

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?

Tân
  • 1
  • 15
  • 56
  • 102
knowiz
  • 11
  • 2
  • 2
    `FileInfo.Exists == false` probably means that the user executing the process has no rights to the file. Double check the file path and check for the effective file permissions. – Cleptus Nov 06 '18 at 08:58
  • 1
    In the relative path you have the file you want to delete? For example if the relative path is .\Folder\myFile.txt and you are exeucting from C:\Users\MyUser\VSProject\, the file C:\Users\MyUser\VSProject\Folder\myFile.txt should exists – Brank Victoria Nov 06 '18 at 08:59
  • Yes I have Uploads/jw2e3wy5.lbqDrain Cleaning.png and I am executing from project folder where the file is but for some reason I am seeing a different path with server name "C:\\Program Files (x86)\\IIS Express\\Uploads\\jw2e3wy5.lbqDrain Cleaning.png" – knowiz Nov 06 '18 at 09:09
  • I can View the images in my website it's only when deleting. Permission is banner.IsReadOnly is set to true how do I change permissions? – knowiz Nov 06 '18 at 09:12

1 Answers1

0

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.

Rahul Neekhra
  • 780
  • 1
  • 9
  • 39