Issue opening file using WinForms application (Open file dialog) where file location is OneDrive

Eswar Chaitanya Darsi 1 Reputation point
2021-10-12T10:52:54.273+00:00

Hi,

I am seeing an issue with File Open Dialog when I try to open a file from OneDrive location mapped on my machine.

Issue / Steps to reproduce:

  1. Copy any file (ex: excel file) to OneDrive
  2. Double click and open the file from OneDrive location to edit
  3. From any windows forms application (.NET Framework 4.8), when I try to open the same file using File dialog window I get an error message "This file is in use. Enter a new name or close the file that's open in another program" public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    openFileDialog1 = new OpenFileDialog();
    }
         private void button1_Click(object sender, EventArgs e)  
         {  
             openFileDialog1.InitialDirectory = "C:\\";  
             var result = openFileDialog1.ShowDialog();  
             if(result == DialogResult.OK)  
             textBox1.Text = openFileDialog1.FileName;  
         }  
     }  
    

139829-capture.png

This issue is not reproducible when I open the file from any local/network shared directory.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,918 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.