"File.Exists" 不存在

"File.Exists" does not exist

我创建了这个 class "XML_Toolbox",我的任何表单都可以使用它来执行我将重复使用的任何关键 XML 操作。话虽如此,这里是 class' 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace Personal_Finance_Manager
{
    class XML_toolbox
    {
        public static void createFile (string filename, string filePath)
        {
            string createPath = filePath + @"\" + filename + ".txt";

            if (file.exists(createPath))
            {
                StreamWriter outfile = new StreamWriter(createPath, true);
            }
            else
            {
                MessageBox.Show("This file already exists!!! Please choose another name!");
            }
        }
    }
}

从另一个表单调用时,所有单独的部分都在工作,直到我添加:

if (file.exists(createPath)) {}

IF 语句。

现在我得到

The name "file" does not exist in the current context

错误。我有

using System.IO;

我还缺少什么?

谢谢!

Class 名称是 File 而不是 file,方法名称是 Exists。 C# 区分大小写。

叫做File,不是file

File.Exists()