none
FileSystem.CurrentDirectory (XP vs Win7) RRS feed

  • Question

  • This is probably something easy, but searching has not provided any help...

    I'm moving my development environment and application from XP to Win7

     Dim XMLFileName As String = My.Computer.FileSystem.CurrentDirectory & "\MktPrefixes.xml"

    When debugging on XP machine I get the following file path:

    "c:\documents and settings\1234\My Documents\Visual Studio 2010\Projects\Blah1\Blah2\Blah3\bin\Debug\MktPrefixes.xml"

    On Win7:

    "C:\Users\1234\Documents\Visual Studio 2010\Projects\Blah1\Blah2\Blah3\bin\Debug\MktPrefixes.xml"

    and then the following error when trying to execute

    XDocument.Load(XMLFileName)

    "Could not find file 'C:\Users\1234\Documents\Visual Studio 2010\Blah1\Blah2\Blah3\bin\Debug\MktPrefixes.xml"

    There is no "Documents" folder following that path on Win7...it is "My Documents", so I'm not how it gets that path.  How do I assure this works on both OS's?

    Appreciate any help

    Monday, March 25, 2013 2:59 PM

Answers

  • I suggest you to check again if the path exists. Maybe it is hidden and you do not see it in Windows Explorer. (In Windows 7 both of the shown paths should be valid and point to the same folder due to specific features of Operating System).

    If you receive an error at Load, then maybe there is no “MktPrefixes.xml” file in Debug subfolder. Use Path.Combine( My.Application.Info.DirectoryPath, “MktPrefixes.xml”) and make sure that the file exists near your .exe.

    You can also insert “MktPrefixes.xml” into your application as a resource.

    • Marked as answer by NervousRex Tuesday, March 26, 2013 6:09 PM
    Tuesday, March 26, 2013 6:22 AM

All replies

  • You should try to avoid hardcoding the documents folder. 

    Use the Special Folder enumeration.]

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx


    Success
    Cor

    • Proposed as answer by BGQQ Monday, March 25, 2013 7:44 PM
    Monday, March 25, 2013 6:42 PM
  • I'm confused how the Specialfolder would be my solution, wouldn't that limit the file to being placed in a specific folder then?

    When debugging, it looks in the bin/ folder

    But when deployed, it looks in the applications install folder where the .exe is run from.  So the path up to the file name is completely dynamic right now.

    SpecialFolder would hardcode the file to a folder, no?

    Monday, March 25, 2013 8:12 PM
  • Try My.Application.Info.DirectoryPath instead of My.Computer.FileSystem.CurrentDirectory.

    Monday, March 25, 2013 8:26 PM
  • Same issue, says the path is    ...\Documents\...

    Monday, March 25, 2013 8:31 PM
  • CurrentPath is the problem.  It changes depending on stuff that is beyond your control. And, as you have discovered, it will be different between development and deployment and that makes testing very difficult.

    Use the SpecialFolder enumeration, but pick a special folder that is going to be consistent, at least for any one version of Windows.  Differences between versions of the OS stil need to be allowed for.   User application data or Common application data are the best folders to use. 

    The actual names will change between systems, but if your deployment uses the same special folders enumeration item then the file will be installed into the correct folder. 

    Monday, March 25, 2013 8:48 PM
  • I suggest you to check again if the path exists. Maybe it is hidden and you do not see it in Windows Explorer. (In Windows 7 both of the shown paths should be valid and point to the same folder due to specific features of Operating System).

    If you receive an error at Load, then maybe there is no “MktPrefixes.xml” file in Debug subfolder. Use Path.Combine( My.Application.Info.DirectoryPath, “MktPrefixes.xml”) and make sure that the file exists near your .exe.

    You can also insert “MktPrefixes.xml” into your application as a resource.

    • Marked as answer by NervousRex Tuesday, March 26, 2013 6:09 PM
    Tuesday, March 26, 2013 6:22 AM