0

I have a file path in the format file://SERVERNAME/FOLDER$/FOLDER/image.jpg. I call System.IO.File.Delete(Server.MapPath(file://SERVERNAME/FOLDER$/FOLDER/image.jpg)) to delete the file, but i get the error file:/SERVERNAME/FOLDER$/FOLDER/image.jpg' is not a valid virtual path. I notice that a '/' is missing and I do not know why. How will I delete such file?

I have tried converting my file path to file:////SERVERNAME//FOLDER$//FOLDER//image.jpg but this did not help. Same thing happens. If I omit the Server.MapPath, I get an error saying URI is not supported.

How to do this please?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jpo
  • 3,959
  • 20
  • 59
  • 102

3 Answers3

12

Since you are doing System.IO.File.Delete I assume you have the permission to delete the file; so you can:

var uri = new Uri("file://SERVERNAME/FOLDER$/FOLDER/image.jpg", UriKind.Absolute);
System.IO.File.Delete(uri.LocalPath);
Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139
1

Have you tried

\\SERVERNAME\FOLDER$\FOLDER\image.jpg

make sure the user account running the application has access to remote machine

Yugz
  • 677
  • 1
  • 10
  • 23
1

Given that you have enough permissions to access that file, you need to convert the given path to \\SERVERNAME\FOLDER$\FOLDER\image.jpg

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121