8

I am trying to select the file which is already opened in quickbook software.

code :

 OpenFileDialog ofdBrowseVInv = new OpenFileDialog();

            ofdBrowseVInv.Title = "Locate QuickBook Company File";
            ofdBrowseVInv.Filter = "QuickBook Company File (*.qbw,*.qbw)|*.qbw;*.qbm";
            ofdBrowseVInv.FileName = "";


           if (ofdBrowseVInv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string strfilename = ofdBrowseVInv.InitialDirectory + ofdBrowseVInv.FileName;

            }

After selecting the file .. i am getting message : File in use

can any one tell me how can i select the file which is already opened...

File in use Screen shot

kame
  • 20,848
  • 33
  • 104
  • 159
Kavitha
  • 1,447
  • 2
  • 22
  • 37
  • The code you have shared will not produce File in use error message, because you are only reading the filename till this point. I believe you are trying to open the file afterwards causing the error. – Riz Mar 12 '14 at 05:33
  • After selecting the file from ShowDiloag... i am getting message... – Kavitha Mar 12 '14 at 05:41
  • Instead of .QBW file if i use .xslx it is working....even if .xslx file open... – Kavitha Mar 12 '14 at 05:44
  • Is the file open for shared read? Otherwise, there wouldn't be anything you can do about that file, so maybe that's why the dialog prevents you from selecting it. – PMF Mar 12 '14 at 05:53

2 Answers2

11

The following code seems to help:

ofdBrowseVInv.ValidateNames = false;

see more here http://social.msdn.microsoft.com/Forums/vstudio/en-US/56fbbf9b-31d5-4e89-be85-83d9cb1d538c/openfiledialog-this-file-is-in-use?forum=netfxbcl

Harry
  • 1,765
  • 1
  • 12
  • 12
1

This code worked for me perfectly.

ofdBrowseVInv.ValidateNames = false;
Ruchi
  • 1,238
  • 11
  • 32
Zico
  • 29
  • 1