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...
The following code seems to help:
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
Locating a file using an open file dialog will not produce the error you describe so I assume that you subsequently are opening the file. Opening a file that is already opened by another process will often fail because the other process has a lock on the file so it may very will be that opening a file that is "already opened" is impossible.
However, if the other process (presumably QuickBooks) has opened the file with read sharing allowed you can open the file by specifying the correct sharing mode. Normally, you will open a file for reading using the
File.OpenRead
method which will useFileShare.Read
. This fails because the other process already has the right to write to the file. However, you can specify the sharing modeFileShare.ReadWrite
by usingFile.Open
method instead:If the other process allows read sharing you will be able to read the file. However, if it does not you will not be able to read the file and there is not much you can do about it except close the file in the other application.
This code worked for me perfectly.