Incorrect output for check existing file in upload in c#
<p>With this asp net page upload file in C# I need to check for duplicates.</p>

<p>I accept 3 files in upload on the server.</p>

<p><a href="https://i.stack.imgur.com/UGW2A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UGW2A.png" alt="enter image description here"></a></p>

<p>After uploading the new 3 files on the server, I have tried to upload the same file 3 files now existing on the server.</p>

<p>For 3 files jpg existing on the server the response code on the <code>Label</code> is incorrect because is :</p>

<blockquote>
  <p>File exist IMG0006A.jpg</p>
</blockquote>

<p>And not</p>

<blockquote>
  <p>File exist IMG0002A.jpg, IMG0005A.jpg, IMG0006A.jpg</p>
</blockquote>

<p>What's the problem ?</p>

<p>Why if I have in the code <code>foreach</code> in <code>Label</code> the output is only for last existing file ?</p>

<p>My code below, thank you in advance for any help.</p>

<pre><code>if (File.Exists(theFileName))
{
    objDir = new DirectoryInfo(Server.MapPath("\\images\\));
    objFI = objDir.GetFiles("*.*");
    iFileCnt = 0;

    if (objFI.Length &gt; 0)
    {
        foreach (FileInfo file in objFI)
        {
            if (file.Name.ToString() == Path.GetFileName(theFileName))
            {
                lblFileList.Text = "File exist " + Path.GetFileName(theFileName);
                iFileCnt += 1;
            }
        }
    }
}
</code></pre>