c# 判断文件是否已使用
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# 判断文件是否已使用的更多相关文章
- 使用c#检测文件正在被那个进程占用 判断文件是否被占用的两种方法
C# 判断文件是否被占用的三种方法 using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.d ...
- python os 命令,及判断文件夹是否存在
使用前 import os导入模块 os模块: os.sep 可以取代操作系统特定的路径分割符 os.linesep 字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...
- C#判断文件及文件夹是否存在并创建(C#判断文件夹存在)
protected void Button1_Click(object sender, EventArgs e) { if (Directory.Exists(Server.MapPath(" ...
- Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)
首先,我们先来认识下CreateFile函数,它的原型如下 HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名的指针 DWORD dwDesired ...
- Java根据字节数据判断文件类型
通常,在WEB系统中,上传文件时都需要做文件的类型校验,大致有如下几种方法: 1. 通过后缀名,如exe,jpg,bmp,rar,zip等等. 2. 通过读取文件,获取文件的Content-type来 ...
- JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤
JAVA之旅(二十八)--File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤 我们可以继续了,今天说下File 一.File概述 文件的操作是非常 ...
- C#判断文件和文件夹是否存在 不存在则创建
using System.IO;string path = @"D:\accountDaoRu\"; if (Directory.Exists(path) == fa ...
- C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建
取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...
- Delphi判断文件是否正在被使用
首先,我们先来认识下CreateFile函数,它的原型如下 HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名的指针 DWORD dwDesired ...
随机推荐
- LeetCode OJ:Search in Rotated Sorted Array(翻转排序数组的查找)
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- Spring整合hibernate:3、使用XML进行声明式的事务管理
配置applicationContext.xml文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...
- SpringXML方式配置bean的集合注入:list,map,properties
新建一个bean,设置相应的集合属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public class Collecti ...
- Ubuntu12.04下samba服务器共享配置
1 . 前置工作 首先保证你的Ubuntu能上网:虚拟机网络连接方式为NAT:虚拟机雨物理机互ping可通: 2. 安装samba sudo apt-get insall samba sudo apt ...
- RHCS高可用集群配置(luci+ricci+fence)
一.什么是RHCS RHCS是Red Hat Cluster Suite的缩写,也就是红帽集群套件,RHCS是一个能够提供高可用性.高可靠性.负载均衡.存储共享且经济廉价的集群工具集合,它将集群 ...
- 移动设备web开发插件iScroll的使用详解
地址:http://blog.nnnv.cn/index.php/archives/65
- 随想录(kgdb的基本原理)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 在linux kernel调试的时候,有一种很方便的调试方法,那就是kgdb.kgdb的本质,就 ...
- ogg高版本到低版本同步
源端ogg版本: [oracle@rac1 ogg]$ ggsci -v Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1 ...
- 安卓开发 报错 错误:This version of android studio is incompatible with the gradle version used. 的解决
本文的解决方法主要参考以下文章: https://blog.csdn.net/sinat_15417921/article/details/51907728 Android 开发总是会遇到各种不知道怎 ...
- 使用jdbc对数据库增删改查(Mysql为例)
一.statement对象介绍 Statement对象的executeUpdate方法,用于向数据库发送增.删.改的sql语句,executeUpdate执行完后,将会返回一个整数. Statemen ...