c# - Delete remote files? -


I have files that I want to delete. Connection can be from file sharing, http and FTP

Example for deleting files:

  // mytest // delete // filename.bin ftp: // Mytest / delete / filename.bin http: //mytest/delete/filename.bin   

Here's what I did:

  Uri target = new Uri (@ "FTP: //mytest/delete/filename.bin"); FileInfo fi = New FileInfo (target.AbsoluteUri); Fi.Delete ();   

The error I get is:

The given path format is not supported

Is there any one Which code can be deleted in all these file types?

I have created a simple code for this task (depending on the thread response).
This input is:

  Uri target = new urie (@ "FTP: //tabletijam/FileServer/upload.bin"); Uri Goal = New Uri (@ "http: //tabletijam/FileServer/upload.bin"); Uri Goal = New Uri (@ "\\ Tabletzism \ File Server \ Upload. Been");   

This code is:

  bool DeleteFileOnServer {URI server URI} {if (serverUri.Scheme == Uri.UriSchemeFtp) {FtpWebRequest request = (FtpWebRequest) WebRequest .Create (serverUri); Request.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse) request.GetResponse (); LblStatus.Content = response.StatusDescription; Response.Close (); Back true; } And if (serverUri.Scheme == Uri.UriSchemeFile) {System.IO.File.Delete (serverUri.LocalPath); Back true; } And if (serverUri.Scheme == Uri.UriSchemeHttp || serverUri.Scheme == Uri.UriSchemeHttps) {HttpWebRequest Request = (HttpWebRequest) WebRequest.Create (serverUri); Request.Method = WebRequestMethods.Http.DeleteFile; HttpWebResponse response = (HttpWebResponse) request.GetResponse (); LblStatus.Content = response.StatusDescription; Response.Close (); Back true; } And {lblStatus.Content = "Unknown Uri plan."; return false; }}   

FTP and file have been deleted successfully DeleteFile in WebRequestMethods.Http .

So my question is, how do I delete the file from this URI?

  http: //tabletijam/FileServer/upload.bin    

Because FileInfo only works with local files, for each connection, you will need special implementation.

For FTP:

  Public Static Bull, DeleteFileOnServer (URI Server URI) {// Server URI parameter should use FTP: / / Plan // In that server file Is the name that is to be removed. // Example: ftp://contoso.com/someFile.txt. // if (serverUri.Scheme! = Uri.UriSchemeFtp) {return false; } // Get the object used to communicate with the server FtpWebRequest request = (FtpWebRequest) WebRequest.Create (serverUri); Request.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse) request.GetResponse (); Console.light line ("remove status: {0}", feedback status description); Response.Close (); Back true; }    

Comments