File Exists - CSharp System.Xml

CSharp examples for System.Xml:XML File

Description

File Exists

Demo Code


using System.Xml.Linq;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;
using System.IO;//from  w w  w.  j av  a  2s .co  m
using System.Collections;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using System;

public class Main{
        // Methods
        public static bool FileExists(string filePath)
        {
            if (File.Exists(filePath))
            {
                return true;
            }
            FileIOPermission permission = null;
            try
            {
                permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, filePath);
            }
            catch
            {
                return false;
            }
            try
            {
                permission.Demand();
            }
            catch (Exception exception)
            {
                //
            }
            return false;
        }
}

Related Tutorials