在C#中验证文件是否存在
在C#中验证文件是否存在
我正在开发一个应用程序。该应用程序应该获得用户的简历,所以我需要一个代码来验证文件是否存在。
我正在使用ASP.NET/C#。
admin 更改状态以发布 2023年5月24日
您可以使用System.IO
命名空间中File
类的Exists
方法来确定是否存在指定的文件:
bool System.IO.File.Exists(string path)
您可以在MSDN上找到文档。
示例:
using System; using System.IO; class Test { public static void Main() { string resumeFile = @"c:\ResumesArchive\923823.txt"; string newFile = @"c:\ResumesImport\newResume.txt"; if (File.Exists(resumeFile)) { File.Copy(resumeFile, newFile); } else { Console.WriteLine("Resume file does not exist."); } } }