string path = Server.MapPath(" PDFs");
bool tfOpenTemp= IsFileInUse(path + " /Doc1.pdf ");
if (!tfOpenTemp)
{ }
else
{
Alert("打印模板已调用,请关闭后进行此操作!");
}
       #region 提示信息
//提示信息 using System.Web.UI;
public void Alert(string str_Message)
{
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), "", "alert('" + str_Message + "');", true);
}
public void Alert(string str_Message, string redirect)
{
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), "", "alert('" + str_Message + "');self.location='" + redirect + "'", true);
}
#endregion
        #region 判断文件是否已使用
public static bool IsFileInUse(string fileName)
{
bool inUse = true;
if (File.Exists(fileName))
{
FileStream fs = null;
try
{
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
inUse = false;
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
finally
{
if (fs != null)
{
fs.Close();
}
}
return inUse; //true表示正在使用,false没有使用
}
else
{
return false; //文件不存在则一定没有被使用
}
}
#endregion

c# 判断文件是否已使用的更多相关文章

  1. 使用c#检测文件正在被那个进程占用 判断文件是否被占用的两种方法

    C# 判断文件是否被占用的三种方法 using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.d ...

  2. python os 命令,及判断文件夹是否存在

    使用前 import os导入模块   os模块: os.sep     可以取代操作系统特定的路径分割符 os.linesep  字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...

  3. C#判断文件及文件夹是否存在并创建(C#判断文件夹存在)

    protected void Button1_Click(object sender, EventArgs e) { if (Directory.Exists(Server.MapPath(" ...

  4. Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)

    首先,我们先来认识下CreateFile函数,它的原型如下   HANDLE CreateFile( LPCTSTR lpFileName,    //指向文件名的指针 DWORD dwDesired ...

  5. Java根据字节数据判断文件类型

    通常,在WEB系统中,上传文件时都需要做文件的类型校验,大致有如下几种方法: 1. 通过后缀名,如exe,jpg,bmp,rar,zip等等. 2. 通过读取文件,获取文件的Content-type来 ...

  6. JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤

    JAVA之旅(二十八)--File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤 我们可以继续了,今天说下File 一.File概述 文件的操作是非常 ...

  7. C#判断文件和文件夹是否存在 不存在则创建

    using System.IO;string path = @"D:\accountDaoRu\";        if (Directory.Exists(path) == fa ...

  8. C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建

    取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...

  9. Delphi判断文件是否正在被使用

    首先,我们先来认识下CreateFile函数,它的原型如下   HANDLE CreateFile( LPCTSTR lpFileName,    //指向文件名的指针 DWORD dwDesired ...

随机推荐

  1. Redis数据结构:SDS

    1. 简单动态字符串(simple dynamic string,SDS)是Redis的默认字符串表示结构,底层的string都是基于SDS实现.Redis基于C语言,并引用了部分C函数. 使用场景: ...

  2. 12.18 aop身份验证

    对所有卖家页面进行身份验证,采用aop编程 步骤:1.获得request 2.查询cookie 3.查询redis 4.查询不通过时,采用抛出异常,捕捉异常,再异常里加入跳转到登陆页面的方法 准备工作 ...

  3. mysql function动态执行不同sql语句

    create procedure cps() begin ) default 'user'; set strSql = concat('select * from ',table_user); pre ...

  4. 剑指offer--43.连续子数组的最大和

    最大子段和,最大能取所有 ---------------------------------------------------------------- 时间限制:1秒 空间限制:32768K 热度 ...

  5. vue.js 源代码学习笔记 ----- 工具方法 share

    /* @flow */ /** * Convert a value to a string that is actually rendered. { .. } [ .. ] 2 => '' */ ...

  6. No module named 'cv2'出错

    当在python 3.6里运行课程里的强化学习程序时,出现如下出错,怎么办呢? >>> = RESTART: D:\work\csdn\tensorflow\DeepLearning ...

  7. CuratorFramework入门指南

    CuratorFramework入门指南 原文地址:https://github.com/Netflix/curator/wiki/Getting-Started CuratorFramework作为 ...

  8. OpenFlow技术白皮书-V1.0

    1.  概述 OpenFlow是由斯坦福大学的Nick McKeown教授在2008年4月ACM Communications Review上发表的一篇论文OpenFlow: enabling inn ...

  9. HDU2604 Queuing 矩阵初识

    Queues and Priority Queues are data structures which are known to most computer scientists. The Queu ...

  10. Docker学习(三)docker容器操作

    上一篇:Docker学习(二)docker镜像操作 容器是基于镜像创建的,说白了把一个镜像运行起来就是容器 查看容器 docker ps 上面什么也没有,因为我们没有正在运行的容器,下面我门启动一个容 ...