C# determines whether the file is in use

 private bool IsFileInUse(string strFileName)
        {
            if (!File.Exists(strFileName))
                return false;
            bool bRet = true;
            FileStream fs = null;
            try
            {
                fs = new FileStream(strFileName, FileMode.Open, FileAccess.Write, FileShare.None);
                bRet = false;
            }
            catch
            {

            }
            finally
            {
                if (fs != null)
                    fs.Close();
            }
            return bRet;
        }

Guess you like

Origin blog.csdn.net/weixin_43935474/article/details/106421392