阅读背景:

为什么File.exists(Filename)语句不起作用?

来源:互联网 

This is my code

这是我的代码

 protected void btnAdd_Click(object sender, EventArgs e)
{
    if (FileUploadControl.HasFile)
    {
        try
        {
            string filename = Path.GetFileName(FileUploadControl.FileName);
            switch(SubDrpDownList.SelectedIndex)
            {
                case 0:
                    if (!File.Exists(filename))
                        FileUploadControl.SaveAs(Server.MapPath("~/Books/Math/") + filename);
                    else if (File.Exists(filename))
                    {
                        throw new DuplicateWaitObjectException();
                    }
                     break;
                case 1:
                    if (!File.Exists(filename))
                    FileUploadControl.SaveAs(Server.MapPath("~/Books/Physics/") + filename);
                    else if (File.Exists(filename))
                    {
                        throw new DuplicateWaitObjectException();
                    }
                    break;
                case 2:
                    if (!File.Exists(filename))
                    FileUploadControl.SaveAs(Server.MapPath("~/Books/Drawing/") + filename);
                    else if (File.Exists(filename))
                    {
                        throw new DuplicateWaitObjectException();
                    }
                    break;
            }
            lblStatus.Text = "Upload status: File uploaded!";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }
}
 protected void btnA



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: