mooman_fl
Centurion
I have done variations on this question before and never really did get the problem sorted.
I am making a component that has a collection class as a property. Among the properties in this class is a filename string that should point to an interface library in the containing program's folder.
It also has a second, nested, collection class as a property. When the filepath is set it looks at the interface library and retrieves the interface names listed in the library.
My initial problem was that the path in the filename string was set by a FindFile dialog, and it set an absolute path serialized in the control to the project directory. This would not do for the end-user at runtime however. I fixed this to just serialize the filename without the path. I did this by using this logic in the "set" for the property:
This works fine during runtime and designtime. The problem comes in the next statements during designtime...
At designtime FileName winds up giving a "file not found" error when you try to go to Design View for the containing form. Turns out the it is putting the path of the DLL as the path to the VS.NET folder. I know WHY it is doing this... just not sure what I should do to get more acceptable behavior.
Is there possible a way just to programmatically get a path to the component library dll itself? Or maybe to get the path to the project directory programmatically at design time?
I am making a component that has a collection class as a property. Among the properties in this class is a filename string that should point to an interface library in the containing program's folder.
It also has a second, nested, collection class as a property. When the filepath is set it looks at the interface library and retrieves the interface names listed in the library.
My initial problem was that the path in the filename string was set by a FindFile dialog, and it set an absolute path serialized in the control to the project directory. This would not do for the end-user at runtime however. I fixed this to just serialize the filename without the path. I did this by using this logic in the "set" for the property:
Visual Basic:
[size=2][color=#008000]'Value is the path and filename returned by the FileNameEditor dialog
[/color][/size][size=2][color=#0000ff]Set[/color][/size][size=2]([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] [color=black]Value[/color] [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2])
[/size][size=2][color=#008000]'Regex determines if the value returned is a complete path.
[/color][/size][size=2][color=#008000]'The only time the path should be complete is when the property
[/color][/size][size=2][color=#008000]'is set by the FileNameEditor. If it is set at runtime via the
[/color][/size][size=2][color=#008000]'serialized value, it will be filename only minus the path.
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] [color=blue]System.Text.RegularExpressions.Regex.IsMatch[/color][color=black](Value,[/color] [/size][size=2][color=#800000]"^[a-zA-Z]:\\.*\..*"[/color][/size][size=2][color=black])[/color] [/size][size=2][color=#0000ff]Then
[/color][/size][size=2][color=#008000]'This retrieves the filename from the complete path.
[/color][/size][size=2][color=black]FileName =[/color] [color=blue]System.IO.Path.GetFileName[/color][color=black](Value)[/color]
[/size][size=2][color=#0000ff]Else
[/color][/size]
[size=2][color=#008000]
[/color][/size][size=2][color=black]FileName =[/color] [color=blue]System.Windows.Forms.Application.StartupPath[/color] [color=black]+[/color] [/size][size=2][color=#800000]"\"[/color][/size][size=2] [color=black]+ Value[/color]
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If[/color][/size]
This works fine during runtime and designtime. The problem comes in the next statements during designtime...
Visual Basic:
[size=2][color=#008000]'Loads the assembly and looks through it for interfaces.
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] [color=black]aASM[/color] [/size][size=2][color=#0000ff]As[/color][/size][size=2] [color=black]System.Reflection.Assembly[/color]
[/size][size=2][color=#008000]'load interface carrying DLL
[/color][/size][size=2][color=black]aASM =[/color] [color=blue]System.Reflection.Assembly.LoadFile[/color][color=black](FileName)[/color]
[/size]
At designtime FileName winds up giving a "file not found" error when you try to go to Design View for the containing form. Turns out the it is putting the path of the DLL as the path to the VS.NET folder. I know WHY it is doing this... just not sure what I should do to get more acceptable behavior.
Is there possible a way just to programmatically get a path to the component library dll itself? Or maybe to get the path to the project directory programmatically at design time?
Last edited: