简体   繁体   English

如何从asp.net中的相对路径删除文件

[英]How to delete file from relative path in asp.net

My Debugging screenshot 我的调试屏幕截图

在此处输入图片说明

I am trying to delete a file in asp.net web 4.7.1. 我正在尝试删除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. 我正在使用FileInfo并使用相对路径检查文件是否存在,这些路径指向Uploads文件夹以及图像全名和扩展名。 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? 如何删除而不必创建第二个数据库字段来存储完整路径?

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). 解决此类问题的最佳方法之一(这样应用程序将不会面临Windows驱动器级别的路径访问或读写访问的任何挑战)。

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. 然后,您可以在代码中使用该虚拟目录相对路径,而不是完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM