PDA

Click to See Complete Forum and Search --> : application.startup path, not exists


steve_rm
May 4th, 2007, 05:04 AM
Hello,

I am using the Compact Framework 2.0

I have an xml document I would like to read and write to.

I have added the xml doc to my project, but how can I gain access to it when I can't use the application.startup path?

Does anyone have any suggestions?

Many thanks,

Steve

Strider
May 4th, 2007, 09:10 AM
Public Function GetApplicationPath() As String
Dim strAppPath As String
strAppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules(0).Full yQualifiedName)
Return strAppPath & "\"
End Function

steve_rm
May 4th, 2007, 11:37 AM
Hello,

Thanks for your help again. I used the code and it ran ok, but got an error message that cannot find the file path.

However, the path i get is \programFile\PDACodeRedWM5 which is returned

PDACodeRedWM5 being the name of my project.

However, this path doesn't exist on my file system. So i got an error saying 'Could not find a part of the path '\C:\Program Files\PDACodeRedWM5\webServiceUrl.xml'.

So i created this actual path on my file system and still got the same error message.

This is my code so you can have a better understanding, I am trying to read in a xml file into a Dataset.

Try
'File the xml file
Dim fileName As String = String.Empty
Dim ds As New DataSet
Dim dv As DataView

Dim path As String
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase )
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules(0).Full yQualifiedName)

'Read in the xml file

fileName = String.Format("{0}\WebServiceURL.xml", path)

ds.ReadXml(fileName)

'Find if a url already exists
dv = New DataView(ds.Tables(0))

If (dv.Count = 0) Then
'This is the first time the application is running, so input from user
Dim objInputURL As New InputURL()
objInputURL.ShowDialog()
Else 'Set the URL to the current web service location
Dim objUrl As New Globals
objUrl.UrlPath = ds.Tables(0).Rows(0)("url").ToString()
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try

If the programFile\PDACodeRedWM5 has not been created why does it give that file path?

The actual path the application is in, is on my D drive.

Many thanks for any help,

Steve

petevick
May 4th, 2007, 12:58 PM
Hi,
there is no concept of drives, so why are you referring to c:\ and d:\ ?

Which line is giving you the error?

Have you checked that the file is in \Program Files\PDACodeRedWM5 as you can get it copied down automatically when you start your app in Visual Studio

Pete

steve_rm
May 4th, 2007, 01:23 PM
Hello Pete,

Thanks for your reply.

The real error message and I should have written this down correctly is: "Could not find file '\Program Files\PDACodeRedWM5\WebServiceURL.xml'."

When i was referring to my D drive, as that is where my project is located on my computer. When I added my xml document I right clicked the project | add new item | xml file. The xml document is contained with my project files.

I guess the reason there is no concept of drives, is because a PDA doesn't have any, is that the reason?

The line that give me the error is: ds.ReadXML(fileName)

Getting back to the problem of the path to the xml document, when I get the path using this line of code:path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase )

it returns: "\Program Files\PDACodeRedWM5"

I have created this path and put the xml document inside, and still get the same error.

This is my first mobile application, so not sure where to store this xml document and how to retrieve it.

Many thanks for your help,

Steve

petevick
May 5th, 2007, 01:05 AM
Hi,
are you sure your file is there?
I have just taken your code, and created a project, set the file WebServiceURL.xml 'Copy to output' as always, ran the project, and it runs fine.
Just checked on the emulator, and the program and the XML file are both in the same place

Pete

steve_rm
May 5th, 2007, 02:21 AM
Thanks for your help Pete.

I changed the copy to output and set it to always. Looks like that did the trick. If you don't mind me asking, what is the purpose of changing it to always?

I did manage to find another method to do this that worked by setting and getting the value from the registry. Code below:
url = CStr(Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\RealitySolutions", "WebServiceUrl", Nothing))

and
Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Software\RealitySolutions", "WebServiceURL", Me.txtURL.Text)


Just to get some expert advice, which do you think is the best method to use. The xml file will never be extended to contain other values, only the url of the web service.

The purpose of this, is just to get a single value and set it by the user.

Thanks for your expert help,

Steve

petevick
May 5th, 2007, 07:54 AM
Hi,
you can also set it to 'copy only if newer', but this only applies to development.

When you deploy, you will need to add the file to the list of files that are deployed on the device

Pete