Hi John Mangam ,
Welcome to the Microsoft Q&A Platform!
The issue you're encountering with file deletion in an Azure App Service is due to the incorrect path being used for accessing the files. From the error message and the file path structure you've shared, it appears that the app is trying to access the files in an invalid directory
(C:\home\site\wwwroot\wwwroot\sample\uploads
), .
Fix Path Construction: Remove the redundant wwwroot
from the path:
private readonly string myUploadFolderPath = Path.Combine(Directory.GetCurrentDirectory(), configuration["mySettings:UploadsFolderPath"]);
Check Permissions: Ensure the App Service has the correct permissions to delete files in the uploads folder.
Use Absolute Path: Use Environment.GetEnvironmentVariable("HOME")
to get the App Service root and construct the path.
private readonly string myUploadFolderPath = Path.Combine(Environment.GetEnvironmentVariable("HOME"), "site", "wwwroot", configuration["mySettings:UploadsFolderPath"]);
Debug the Path: Log the constructed path to verify it's correct
Console.WriteLine("Uploads folder path: " + myUploadFolderPath);
If the answer is helpful, please click "Accept Answer" and kindly upvote it.