打开已在窗口资源管理器中打开的文件 [英] Open File Which is already open in window explorer

查看:201
本文介绍了打开已在窗口资源管理器中打开的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenFileDialog打开文件.

I am trying to open a file using OpenFileDialog.

if (openFileDialog1.FileName != "" && resultSaveDialog == System.Windows.Forms.DialogResult.OK)
        {
            openFileDialog1.OpenFile(); // Throw Exception Here
            txtFileName.Text = openFileDialog1.SafeFileName;                
        }

但是如果文件已经在浏览窗口中打开,则会引发以下异常

But if file is already opened in window explored it throws me following exception

该进程无法访问文件 'D:\ Projects \ CDR_RAW_FILES \ GroupData \ 8859511378.xls',因为它是 被另一个进程使用.

The process cannot access the file 'D:\Projects\CDR_RAW_FILES\GroupData\8859511378.xls' because it is being used by another process.

即使文件已在窗口资源管理器中打开,也可以使用OpenFileDialog打开文件.

Is it possible to open the file Using OpenFileDialog even if file has already opened in window Explorer.

推荐答案

好,如果您只需要选定文件"名称及其路径,请尝试如下操作,它将为您提供帮助...

Ok, If you just need the Selected File name and its path, Then try like below, It will help you...

if (openFileDialog1.FileName != "" && resultSaveDialog == System.Windows.Forms.DialogResult.OK)
{
 string path = Path.GetDirectoryName(openFileDialog1.FileName);
 string filename = Path.GetFileName(openFileDialog1.FileName);
 txtFileName.Text = filename;
}

这篇关于打开已在窗口资源管理器中打开的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆