用C#打开一个文件(比如,word,execle,txt等),当下次再打开时,我怎么判断已经被打开,并且显示出来已经打开的文件,就资源管理器里做哪样,双击打开一个文件,再双击,显示已经打开的文件

解决方案 »

  1.   


    正确! 但如果比如打开excel ,再关闭,如果不能catch 到这个关闭动作,就不能删除记事本中的记录
      

  2.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Runtime.InteropServices;namespace test
    {
    /// <summary>
    /// AjaxRecive 的摘要说明。
    /// </summary>
    public class AjaxRecive : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    //return Request.QueryString["name"].ToString();
    } [DllImport("kernel32.dll")]
    public static extern IntPtr _lopen(string lpPathName, int iReadWrite); [DllImport("kernel32.dll")]
    public static extern bool CloseHandle(IntPtr hObject); public const int OF_READWRITE = 2;
    public const int OF_SHARE_DENY_NONE = 0x40;
    public readonly IntPtr HFILE_ERROR = new IntPtr(-1); #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string strFile = @"D:\test.txt";
    IntPtr oHandle = _lopen(strFile, OF_READWRITE | OF_SHARE_DENY_NONE);
    if(oHandle == HFILE_ERROR)
    {
    Response.Write("文件被占用!");
    }
    else
    {
    CloseHandle(oHandle);
    Response.Write("文件没有被占用!");
    }
    }
    }
    }
      

  3.   

     我觉得7楼可以
     
      对于系统打开文件后 应该有相关信息 , 若word打开后有临时文件, 但具体我也不知道 
     
      帮你顶