各位能不告诉我怎样检测文件是否存在,我的文件名是从数据库中取的

解决方案 »

  1.   

    File.Exists 方法  [C#]请参见
    File 类 | File 成员 | System.IO 命名空间 | 使用 I/O | 从文件读取文本 | 向文件写入文本 | File 成员(Visual J# 语法) | C++ 托管扩展编程 
    要求
    平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准.NET Framework 安全性:  FileIOPermission。关联的枚举:FileIOPermissionAccess.Read 
    语言
    C#C++JScriptVisual Basic全部显示
    确定指定的文件是否存在。[Visual Basic]
    Public Shared Function Exists( _
       ByVal path As String _
    ) As Boolean[C#]
    public static bool Exists(
       string path
    );[C++]
    public: static bool Exists(
       String* path
    );[JScript]
    public static function Exists(
       path : String
    ) : Boolean;参数
    path 
    要检查的文件。 
    返回值
    如果调用方具有要求的权限并且 path 包含现有文件的名称,则为 true;否则为 false。如果 path 为空引用(Visual Basic 中为 Nothing)或零长度字符串,则此方法也返回 false。如果调用方不具有读取指定文件所需的足够权限,则不引发异常并且该方法返回 false,这与 path 是否存在无关。
      

  2.   

    using System.IO;if(File.Exist(yourFilePath))
    {
       DO something;
    }