开发者

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)
          开发者_JS百科          {
                        i++;
                    }
                }


    Label1.Text = "Completed";


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜