public IActionResult DeleteFile(string userId, string fileName) { // Get a reference to a share and then create it ShareClient share = new ShareClient(Secret.AzureConnectionString, Secret.AzureFileShareName); if (!share.Exists()) { share.Create(); } // Get a reference to a directory and create it ShareDirectoryClient directory = share.GetDirectoryClient(Auth0Utils.GetUserFolder()); if (!directory.Exists()) { directory.Create(); } // Get a reference to a file and upload it ShareFileClient fileClient = directory.GetFileClient(fileName); fileClient.DeleteIfExists(); return(Ok()); }
/// <summary> /// Deletes a file in the current directory /// </summary> /// <param name="filename">The name of the file to delete</param> /// <returns>True if successful. False if not. Any exceptions are thrown.</returns> public bool FileDelete(string filename) { if (FileShare == null || Directory == null) { throw new Exception("Cannot delete Azure file: " + filename + " (null share or directory)."); } if (!this.FileExists(filename)) { throw new Exception("Cannot delete Azure file: " + filename + " because it isn't there!"); } // Get a reference to the file ShareFileClient file = Directory.GetFileClient(filename); // Check whether it exists. bool ret = file.DeleteIfExists(); return(ret); }