Cannot find file issue

Cannot find file issue

Anonymous
Not applicable
602 Views
4 Replies
Message 1 of 5

Cannot find file issue

Anonymous
Not applicable

Hi people,

     Ok, so I have my DLL working fine, but have decided to use an *.ini txt file to preload past configuration settings and defaults from.

 

I have the *.ini file in the same folder as the DLL but get an error message saying it cant be found!!

 

        'READ TBM_conf.ini FILE TO POPULATE THE MAJORITY OF INTERNAL VARIABLES FOR PROCESSING

        Dim All_Lines As New List(Of String)
        Dim ConfigFile As New IO.StreamReader("TBMconfig.ini")
        Dim OriginalString As String
        OriginalString = ConfigFile.ReadLine
        Do Until String.IsNullOrEmpty(OriginalString)
        Loop
        ConfigFile.Close()

Any thoughts chaps...

 

Regards

Les

0 Likes
603 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

IMO, you should code your app to find the data file in a predefined searching logic, such as the same folder as the DLL is in, the user's Windows profile data location, and so on. In your case, if you decide the data file must be in the same folder as the DLL is, you can text its existence before using it. Something like:

 

Private Function FindConfigurationFile() As String

  Dim asm As Assembly=Assembly.GetExecutingAssembly()

  Dim filePath=asm.Location & "\TBMconfig.ini"

  If Not File.Exists(filePath) Then

    ''Search other places, if necessary, or throw exception

    Throw New FileNotFoundException("Cannot find configuration file!")

  Else

    Return filePath

  End If

End Function

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5

_gile
Consultant
Consultant

Hi,

 

Try like this (not sure about VB syntax)

 

Imports System.IO
'...

'READ TBM_conf.ini FILE TO POPULATE THE MAJORITY OF INTERNAL VARIABLES FOR PROCESSING

Dim assemblyPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
Dim configFilePath As String = Path.Combine(Path.GetDirectoryName(assemblyPath), "TBMconfig.ini")
Dim All_Lines As New List(Of String)
Dim ConfigFile As New StreamReader(configFilePath)
Dim OriginalString As String
OriginalString = ConfigFile.ReadLine
Do Until String.IsNullOrEmpty(OriginalString)
Loop
ConfigFile.Close()


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 5

fieldguy
Advisor
Advisor

you can also use an embedded resource >>here<<

0 Likes
Message 5 of 5

Anonymous
Not applicable

Excellent response guys, I started work on this yesterday...and got to this.

 

        'READ TBM_conf.ini FILE TO POPULATE THE MAJORITY OF INTERNAL VARIABLES FOR PROCESSING
Try
        'Dim All_Lines() As List(Of String)
        'Dim ConfigFile As New IO.StreamReader("TBMconf.ini")
        'Dim OriginalString As String
        'OriginalString = ConfigFile.ReadLine
        'Do Until String.IsNullOrEmpty(OriginalString)
        'Loop
        'ConfigFile.Close()
....

Which caused AutoCAD to hang, and after a few attempts at changing things AutoCAD just refused to open at all, with a Fatal Error message...Had to use the install disc to repair it, so lost a fair bit of time...but we're up and running again and I commented the offending section out till I've got a better method for populating my GUI textboxes. It was ok whist it couldn't find the file, but as soon as I sorted that (miss spelt filename), it died on me.

 

Really appreciate your replies and will come back to it when I've sorted myself out. I can see where it would go into a permanent loop now, as I write this, (the Do Loop is after the 'read' )but after losing my CAD yesterday, all code went out the window whilst the 'main prog' was fixed.

 

 

Regards

Les

0 Likes