1

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";
7
  • Welcome to StackOverflow. You should post relevant source code so we can actually help you with your problem, since your current question lacks enough critical information to help us resolve your problem. Commented Apr 4, 2011 at 23:06
  • 2
    @user: edit your question to include the code that performs the deletion. Be sure to include any errors and their exact wording. Commented Apr 4, 2011 at 23:08
  • Please put the error text in too. Commented Apr 4, 2011 at 23:13
  • I doesn't get any error but the files remain as it is. Commented Apr 4, 2011 at 23:14
  • I wonder if it's because you're swallowing the exception... Commented Apr 4, 2011 at 23:16

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.