12 Replies - 568 Views - Last Post: 13 April 2019 - 11:04 AM Rate Topic: -----

#1 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

openfiledialog causes an I/O error

Posted 09 April 2019 - 10:23 PM

My program can open a Data file in 2 ways

1. through the recent items list in a File Menu
2. using the Windows openfiledialog

Having opened the file and extracted the info the file is closed in both options.

A user has the option of changing the name of the folder that the data was in,
If I used option 1 to access the Data file, there is NO issue.
If I used option 2 to access the Data file, it gives me error no. 57 a device I/O error.

Tried reset and dispose of the openfiledialog, but can't get past it

FileIO.FileSystem.RenameDirectory(dir2, FNM)


dir2 is the path and name of existing folder
FNM is the new name to change to

Any ideas appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: openfiledialog causes an I/O error

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: openfiledialog causes an I/O error

Posted 09 April 2019 - 11:55 PM

You should post more relevant code than a single line.
Was This Post Helpful? 0
  • +
  • -

#3 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

Re: openfiledialog causes an I/O error

Posted 10 April 2019 - 12:31 AM

I can't see that it's a problem with coding, more likely a quirk with the openfiledialog.that someone more experienced than me may know of.

Both the options allow the data file to be accessed.

Tthere are no open files within the folder.

It's as if the folder itself has become readonly or a security issue.

	
			Dim OpenCompany As New OpenFileDialog()

			OpenCompany.InitialDirectory = dir
			OpenCompany.Title = "Open Company Data File"
			OpenCompany.Filter = "Company Files (*.dco *.dc1)|*.dco;*.dc1|Most Recent Save (*.dco)|*.dco|Previous Save (*.dc1)|*.dc1"
			'																				and  if needed >  |All Files (*.*)|*.*  after dc1
			OpenCompany.FilterIndex = 1

			If OpenCompany.ShowDialog = DialogResult.OK Then
				CFQ = OpenCompany.FileName
			End If



Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: openfiledialog causes an I/O error

Posted 10 April 2019 - 01:43 AM

I wouldn't think it was a quirk with the dialog.

It is more likely that the file is not fully closed and disposed off perhaps causing the system to consider the folder in use, not allowing it to be renamed. Your further code also shows a file extension of dco or dc1 which I have not encountered before (rather than a .dat or similar file).

The dialog could also be disposed of during debugging.

For debugging I would try a simple Rename Directory (disassociated from a particular file) with a range of locations. This should determine that is isn't an issue with the renaming itself.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,870
  • Joined: 12-June 08

Re: openfiledialog causes an I/O error

Posted 10 April 2019 - 06:50 AM

Please copy/paste the entire error message.
Was This Post Helpful? 0
  • +
  • -

#6 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 122
  • View blog
  • Posts: 679
  • Joined: 01-October 08

Re: openfiledialog causes an I/O error

Posted 10 April 2019 - 09:13 AM

View Postmodi123_1, on 10 April 2019 - 08:50 AM, said:

Please copy/paste the entire error message.


And the line you get the error on.
Was This Post Helpful? 0
  • +
  • -

#7 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

Re: openfiledialog causes an I/O error

Posted 10 April 2019 - 05:48 PM

Hi

At 'Stop' in catch Exception, I examined the 2 files within the folder whilst outside the program and found that they could be edited and saved without issue. The folder could not however be name changed here either in my File manager program 'Total Commander'.

			dir9 = dir & "\" & FNM
			If System.IO.Directory.Exists(dir9) Then Exit Sub
			Try
				FileIO.FileSystem.RenameDirectory(dir2, FNM)
			Catch ex As Exception
				enu = Err.Number
				Stop
			End Try





ErrorMessage:

System.IO.IOException was unhandled
Message=The process cannot access the file because it is being used by another process.
Source=mscorlib
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: openfiledialog causes an I/O error

Posted 11 April 2019 - 12:19 AM

Quote

The folder could not however be name changed here either in my File manager program 'Total Commander'.

Are you confirming that you cannot rename a folder just by right-clicking it? If so, does it give you some message? If it says that it is in use then I would try again after a reboot.

Did you, as suggested, try renaming a couple of different sample/test folders?

You need to distinguish whether there is a problem specifically with renaming a folder (any folder, or just specific ones), or with your code that attempts to do more than just renaming.
Was This Post Helpful? 0
  • +
  • -

#9 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

Re: openfiledialog causes an I/O error

Posted 11 April 2019 - 12:55 AM

Hi

Having interrupted the program immediately after the error, I ascertained independently of the program running in debug mode, that indeed the folder in question cannot be renamed.
I checked absolutely that it is NOT due to open files within that folder.

Prior to the error and within the program, I had another folder nearby have it's name changed without an issue.


I'm thinking of doing a work around and write my own file dialog.
Was This Post Helpful? 0
  • +
  • -

#10 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

Re: openfiledialog causes an I/O error

Posted 11 April 2019 - 01:17 PM

SUCCESS !

After examining all the properties of the OPENFILEDIALOG, I found the answer

			Dim OpenCompany As New OpenFileDialog()

			OpenCompany.InitialDirectory = dir
			OpenCompany.RestoreDirectory = True




The last line I added PRIOR to the openfiledialog opening
Seems there are a lot of GET/SET properties pertaining to this dialog box

Hope this helps others
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,870
  • Joined: 12-June 08

Re: openfiledialog causes an I/O error

Posted 13 April 2019 - 06:52 AM

@demac430 - ease up on the reputation system if you not fully comfortable to use it. Folk asking for clarification about the actual error message does not warrant a down vote. :^:
Was This Post Helpful? 0
  • +
  • -

#12 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 04-January 14

Re: openfiledialog causes an I/O error

Posted 13 April 2019 - 09:19 AM

Ok

I would like mine increased having found my own answer without help

If you can't provide help to a precisely worded problem then don't reply at all please

thanks
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,870
  • Joined: 12-June 08

Re: openfiledialog causes an I/O error

Posted 13 April 2019 - 11:04 AM

Look sport - folk can ask for clarification, and should not be penalized. Continuing with the mistaken belief otherwise will put you on the road to losing the ability to use the rep system.

If you are unclear on the point then I would think it would best to avoid utilizing the rep system completely until you are. :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1