user691959
user691959

Reputation: 11

file cannot be delete from asp.net

Hello guys I a webproject in asp.net my project worked fine in my pc but after uploading it to a iis server it is not working. My webproject is to delete a file,

string s;
    int i;
    s = Environment.GetEnvironmentVariable("temp"); ;

            string[] prefetchtlist = System.IO.Directory.GetFiles(s, "*.*");

                for (i = 0; i < prefetchtlist.Length; i++)
                {
                    try
                    {
                        System.IO.File.Delete(prefetchtlist[i]);
                    }
                    catch (Exception)
                    {
                        i++;
                    }
                }


    Label1.Text = "Completed";

Upvotes: 1

Views: 289

Answers (1)

John Rasch
John Rasch

Reputation: 63435

The file may not delete for a variety of reasons. Remove the try/catch block and see what exception is displayed by your web server.

Also, if an exception is caught, the next file in your array will be skipped because you have i++ in the catch block - you don't need that there because i will just get incremented again when execution returns to the top of the for loop.

Upvotes: 1

Related Questions