0

以下代码传输文件成功,但未在标签中打印已传输。尽管其他检查显示完美。这里面有什么逻辑错误吗?

        if (txtFile1.HasFile)
        {
        var folderfile1 = Server.MapPath("~/files/Operations_Support/IMSI");
        string flFile1 = txtFile1.PostedFile.FileName;
        string saveflFile1 = folderfile1 + "\\" + System.IO.Path.GetFileName(flFile1);

        FileInfo Finfo = new FileInfo(txtFile1.PostedFile.FileName);
        if (Finfo.Extension.ToLower() == ".txt")
        {
            if (txtFile1.PostedFile.ContentLength < 1024)
            {
                //if (!File.Exists(folderfile1))
                if (Directory.GetFiles(folderfile1).Length == 0)
                {
                    txtFile1.SaveAs(saveflFile1);
                    //lbFile1.Visible = true;
                    lbFile1.Text = "Upload status: IMSI file transfered successfully";
                }

                else
                {
                    lbFile1.Text = "Upload status: Please wait until the previous file is processed";
                }

            }
            else
                lbFile1.Text = "Upload status: The file has to be less than 1 kb!";
        }
        else
            lbFile1.Text = "Upload status: Only Text files are accepted!";
    }
    else
    {
        lbFile1.Visible = true;
        lbFile1.Text = "Upload status: Please select file";
    }
4

2 回答 2

0

使用 File.Exists 方法

http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

于 2012-08-13T08:27:47.907 回答
0

像这样使用File.Exists

var folderfile4 = Server.MapPath("~/files/Path");
string saveflFile4 = folderfile4 + "\\" + System.IO.Path.GetFileName(flFile4);
if(!File.Exists(saveflFile4))
    txtFile4.SaveAs(saveflFile4);
else
    txtError.Text = "File exists";

Server.MapPath返回服务器上的物理路径,因此您可以使用它File.Exists来检查文件是否存在。

于 2012-08-13T08:35:07.860 回答