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. LeetCode OJ:ZigZag Conversion(字符串的Z字型转换)

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  2. SQL Plus常用命令

    1.常用命令:显示当前用户名:show user登录到数据库:conn[etc] 用户名/密码@网络[as sysdba / as sysoper]   简单写法:conn 用户名/密码    con ...

  3. java基础 题和知识点总结, 关于String s是否默认初始化为null......,new一个对象和类静态域,是不是在内存中不是一个地方

    一道笔试题 22. 下面代码的运行结果为:() import java.io.*; import java.util.*; public class foo{ public static void m ...

  4. ZK单机最简配置

    修改zk home/conf下的zoo_sample.cfg,重新命名为zoo.cfg. 修改配置为: dataDir=/root/data/zookeeper-data clientPort=218 ...

  5. EP-N8530S USB WIFI 驱动移植

    /*********************************************************************** * EP-N8530S USB WIFI 驱动移植 * ...

  6. WKInterfaceTable实例化出现的一系列

    让我摆一个姿势,缓慢伸出我的右手,面向swift,做"欲扶眼镜"状!!! 正题 闲话不想说了,实例化WKInterfaceTable的时候会报错,实例化代码如下: let row ...

  7. Sprint Boot 学习Q&A

    [ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.1.11:revision (default) on ...

  8. Android学习笔记之Toast详解

    1. 贴一段Android API-Toast Toast public class Toast  extends Object java.lang.Object ↳ android.widget.T ...

  9. 监听器(Listener)学习(二)

    一.监听域对象中属性的变更的监听器 域对象中属性的变更的事件监听器就是用来监听 ServletContext, HttpSession, HttpServletRequest 这三个对象中的属性变更信 ...

  10. FastJson的一些使用

    前言 最近经常使用json的一些转换,使用的是fastjson,所以就对fastjson进行了一些汇总,记录下来. 正文 主要的api 首先是一些类库的说明: SerializeWriter:相当于S ...