Results 1 to 8 of 8

Thread: application.startup path, not exists

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    application.startup path, not exists

    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
    steve

  2. #2
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: application.startup path, not exists

    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
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: application.startup path, not exists

    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.

    Code:
    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).FullyQualifiedName)
    
                '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
    steve

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: application.startup path, not exists

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: application.startup path, not exists

    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:
    Code:
    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:
    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
    Last edited by steve_rm; May 4th, 2007 at 01:32 PM.
    steve

  6. #6
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: application.startup path, not exists

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: application.startup path, not exists

    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:
    vb Code:
    1. url = CStr(Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\RealitySolutions", "WebServiceUrl", Nothing))
    2.  
    3. and
    4.          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
    steve

  8. #8
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: application.startup path, not exists

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width