验证是否文件在C#中的存在与否 [英] Verify if file exists or not in C#

查看:99
本文介绍了验证是否文件在C#中的存在与否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序。该应用程序应该从用户的简历,所以我需要一个code,以验证文件是否存在。

I am working on an application. That application should get the resume from the users, so that I need a code to verify whether a file exists or not.

我使用ASP.NET / C#。

I'm using ASP.NET / C#.

推荐答案

您可以判断是否存在指定的文件中使用的存在方法文件类中的 System.IO 命名空间:

You can determine whether a specified file exists using the Exists method of the File class in the System.IO namespace:

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.");
        }
    }
}

这篇关于验证是否文件在C#中的存在与否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆