Deleting files on a mapped drive using c# and IIS

144 views Asked by At

I currently have a function on one of my Blazor pages that will allow a user to type in a file path and clear some files both on the users computer as well as mapped drives. This works through visual studio when I run it just fine. The problem is when I use IIS to host this application it no longer can delete these files using File.Delete( string of the path name ). It still can delete files on the computer it's being hosted on but not any of the files of the other computers that I was able to delete in debug mode using visual studio 2022. I tried typing in the path name as both the drive it was mapped as (ex: R:\Users\test) and using the IP address (ex: \123.456.78.89\C:\Users\test) and neither did anything.

Is this possible using IIS? Do i have to change any of the settings for my application to be able to find and delete these files?

snippet of c# function just incase:

 public async Task ClearFiles()
    {
        var pathName = FileFilter.PathName;
        FileInfo[] files = SortFiles(pathName);

        try
        {
            if(FileFilter.Filter == "all")
            {
                //will clear all files based on the extension(s) entered
                foreach(var file in files)
                {
                    if(file.Extension == FileFilter.Extension || FileFilter.Extension == "all")
                    {
                        try
                        {
                            File.Delete(file.ToString());
                        }
                        catch (Exception ex)
                        {
                            logger.LogError(ex.Message);
                            Toast = Toast.Bad("Error deleting a file");
                        }

                    }

                }
            }

.
.
.
0

There are 0 answers