当我需要从Web服务器上的目录中删除一些图像文件时,我有一些可以正常工作的代码:
Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL")
Dim physicalName = Server.MapPath(ImageURL)
oUpload.DeleteFileFromServer(physicalName, iAdid, iImgID)
..但是当在单独的线程中以设置的时间间隔运行的维护任务确定需要删除上述文件时,我遇到了问题:
Dim ImageURL As String = dsImage.Tables(0).Rows(i - 1).Item("ImageURL")
Dim iImgID As Integer = dsImage.Tables(0).Rows(i - 1).Item("ImageId")
Dim physicalName As String = HttpContext.Current.Server.MapPath(ImageURL)
oUpload.DeleteFileFromServer(physicalName, iAdID, iImgID)
在后一种情况下,HttpContext.Current.Server.MapPath(ImageURL)的值为Nothing。
有没有办法获得这种情况的完整路径?
最佳答案
假设路径是相对的,则单独的进程将不知道它们与哪个Web应用程序相对。在这种情况下,您将需要将其存储在配置中,然后将两者附加在一起或在〜/上执行字符串替换
关于asp.net - HTTPContext .Current为空时如何使用Server.MapPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4742257/