当前位置:编程学习 > C#/ASP.NET >>

C# 检查文件是否正在使用

[csharp]
/// <summary> 
        /// 检查文件是否正在使用 
        /// </summary> 
        /// <param name="fileName"></param> 
        /// <returns></returns> 
        public static bool IsFileInUse(string fileName) 
        { 
            try 
            { 
                bool inUse = true; 
                FileStream fs = null; 
                try 
                { 
                    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, 
                    FileShare.None); 
                    inUse = false; 
                } 
                catch 
                { 
                } 
                finally 
                { 
                    if (fs != null) 
                        fs.Close(); 
                } 
                return inUse;//true表示正在使用,false没有使用 
            } 
            catch { } 
            return false; 
        } 
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,