RT,最好代码,代码给全部分!!!谢谢!!!

解决方案 »

  1.   

    try
    {
    File.Move(""); 
    }
    catch{}
    修改文件名称

    using System.Runtime.InteropServices;[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);
      

  2.   

    wuyq11的代码可以实现。下面再给一段代码备用自动搜寻所有打开文件,并关闭using System; 
    using System.Runtime.InteropServices; 
    using Word; //Add Com Reference: Microsoft Word 10.0 Object Library namespace CloseDocSample 

    /// <summary> 
    /// Summary description for Class1. 
    /// </summary> 
    class Class1 

    /// <summary> 
    /// The main entry point for the application. 
    /// </summary> 
    [STAThread] 
    static void Main(string[] args) 

    //Define parameter value for winword 
    object oMissing = System.Reflection.Missing.Value; //Find the exist winword application 
    Word.Application winObj = (Word.Application)Marshal.GetActiveObject("Word.Application"); //Close the application 
    winObj.Quit(ref oMissing, ref oMissing, ref oMissing); //Release object 
    System.Runtime.InteropServices.Marshal.ReleaseComObject(winObj); 
    winObj = null; 


      

  3.   

    再补充一下,和wuyq11的代码差不多using System.IO;
    using System.Runtime.InteropServices;[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);
    private void button1_Click(object sender, EventArgs e)
    {
        string vFileName = @"c:\temp\temp.bmp";
        if (!File.Exists(vFileName))
        {
            MessageBox.Show("文件都不存在,你就不要拿来耍了");
            return;
        }
        IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE);
        if (vHandle == HFILE_ERROR)
        {
            MessageBox.Show("文件被占用!");
            return;
        }
        CloseHandle(vHandle);
        MessageBox.Show("没有被占用!");
    }
      

  4.   

    文件是否打开,楼上的方法可行。关闭打开的进程,需要根据不同的应用程序分别做处理。如:“pagefile”系统文件需要关闭电脑重启。
      

  5.   

    开了个新帖子,这里的人都有分。
    http://topic.csdn.net/u/20100420/09/4653271e-6f85-4c49-87ae-fa63fd34fbf4.html
      

  6.   

    再打开一次,try{打开文件} catch{关闭文件}