User controls and relative paths

P

Paul Bromley

I am trying to get somewhere with user controls and have come up against an
obstacle with using relative paths.

I have a dataset in my user control, and have tried to enter the path with
the following:-

dsResultsTable.ReadXml(Application.StartupPath &
"\Textfiles\ResultsTable.xml")

It does not like this, as it takes the application path to be C:\Program
Files\Microsoft Visual Studio .NET\Common7\IDE\devenv.exe.
I have also tried to send the path into the user control as a variable,
using a property - it does not like this either, as it is again looking for
the path above as I try and place the control on my page..
Can anyone point me to a possible solution and explain where I am going
wrong. Why cannot I pass the path in as a property??

ResultsPathXML is being sent to the user control as
(Application.StartupPath & "\Textfiles\ResultsTable.xml"), and I have this
in the Load of my form that is using the control.


Finally are there any good - ? web-based resources to help me with user
controls, using the Usercontrol class, as I think that this will avoid me
doing a lot of repetitive coding in my applications.

Many thanks - Paul Bromley

Public Class ctlSendResultsEMIS
Inherits System.Windows.Forms.UserControl
Private sLabFilter As String
Private sLabResult As String
Private sLabCode As String
Private dsResultsTable As New DataSet()
Private dvResultsTable As New Data.DataView()
Private sResultsPath As String '= (Application.StartupPath &
"\Textfiles\ResultsTable.xml")


Property ResultsPathXML() As String
Get ' Retrieves the value of the private variable.
Return sResultsPath
End Get ' Stores the selected value in the private variable txtTrialText
Set(ByVal Value As String)
sResultsPath = Value
End Set
End Property


Later in the code:-

Private Sub ctlSendResultsEMIS_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dsResultsTable.ReadXml(sResultsPath)
dvResultsTable = dsResultsTable.Tables(0).DefaultView '.DefaultView
GridResults.DataSource = dvResultsTable
End Sub
 
Y

yEaH rIgHt

I tried you code and it worked. Would it be possible for you to post
more code?
 
P

Paul Bromley

Hi,

There is not a great deal more to the code. I have few textboxes and
command buttons on the user control and a grid control. The grid is
populated from the dataset. I then use a command button and the contents of
the textbox to filter the grid. I am presntly using VS.NET 2002 - not sure
if that is where the problem lies. As soon as I try to place the user
control on a form, I get the error re the path.

Many thanks

Paul Bromley
 
Y

yEaH rIgHt

Try this, it might help.

Right click on the Project Solution and select Properties. Open the
Common Properties folder then select Debug Source Files. If devenv.exe
is listed in the box, delete it.
 
P

Paul Bromley

Thanks for the input - unfortunately it did not help. I found that I needed
to delete ALL references to the path, and then to place the control in my
project. I then amend the paths and rebuild the control and then things work
OK. I assume that this may well be abug in VB.Net 2002. I have justs
subscribed to MSDN Professional and so when I get home I will see if
upgrading to 2003 resolves the matter. Many thanks - thought that this may
help others in the same situtaion and save them some time.

Paul Bromley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top