Update datasources for layers in an MXD

2048
5
01-24-2011 03:07 PM
Highlighted
New Contributor III
My environment...
Windows 7 32-bit (and 64-bit as you'll see later)
Visual Studio 2008
Visual Basic.NET
ArcObjects 9.3 (and Service Pack if any)

For the quickest, easiest way to understand what I am asking, please see the attached picture and follow along as I reference the pic.

As you can see, there are 2 highlighted items. My issue comes about as a result of trying to use this MXD on a Windows 7 64-bit system. It works fine on Windows 7 32-bit because the paths are correct, however, on a Windows 7 64-bit system, Microsoft decided to completely screw up their paths causing much heartache to millions of developers migrating to Windows 7 64-bit.

On a Windows 7 32-bit system...
The parcel layer's datasource per the picture is...
C:\Program Files\Assessor\Common\GIS\weeklyparcel.gdb

Several other layer's datasources per the picture are...
C:\Program Files\Assessor\Common\GIS


However, on a Windows 7 64-bit system...
The parcel layer's datasource is actually located here...
C:\Program Files (x86)\Assessor\Common\GIS\weeklyparcel.gdb

Several other layer's datasources are actually located here...
C:\Program Files (x86)\Assessor\Common\GIS

I would like to be able to simply update these paths as needed. I have code that tells me whether I am on a 32-bit O.S. or a 64-bit O.S. but I have no idea how to update these datasources through ArcObjects .NET code

So that's my question... how do I update these paths on-the-fly using ArcObjects .NET, so that I don't have to have one MXD for 64-bit version of Windows, and another MXD for the 32-bit version of Windows.

Thanks a lot.
Reply
0 Kudos
5 Replies
Highlighted
Regular Contributor III
Possible solutions:

1) Reference the data using a UNC path.  For example, \\machine\share\file.extension.
2) Put the data in a path which is not based on Program Files.  Why not use C:\Assessor?
3) Use symbolic links to make the paths the same, e.g. using junction or mklink.  If you do this then you can install the data to different locations but reference it using the same symbolic (or logical) link
Reply
0 Kudos
Highlighted
New Contributor III
Possible solutions:

1) Reference the data using a UNC path.  For example, \\machine\share\file.extension.
2) Put the data in a path which is not based on Program Files.  Why not use C:\Assessor?
3) Use symbolic links to make the paths the same, e.g. using junction or mklink.  If you do this then you can install the data to different locations but reference it using the same symbolic (or logical) link


Because we have tons of apps that are already dependent on C:\Program Files\... it's not practical at this point to change it, so (1) and (2) aren't feasible.  I'm not sure how (3) works, but I'll take a look at that.  I'd still like to know how to update the datasources through code.
Reply
0 Kudos
Highlighted
Regular Contributor III
There are classes in the .NET Framework for handling this sort of thing.  Because the location of system and special Windows folders differs from OS to OS, you should use these built-in classes when dealing with the file system.  The location of the Program Files folder can be determined in Visual Basic with the following code:

Dim programFilesPath As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles

You can then append any subdirectory paths and/or filenames as needed.
Reply
0 Kudos
Highlighted
New Contributor III
There are classes in the .NET Framework for handling this sort of thing.  Because the location of system and special Windows folders differs from OS to OS, you should use these built-in classes when dealing with the file system.  The location of the Program Files folder can be determined in Visual Basic with the following code:

Dim programFilesPath As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles

You can then append any subdirectory paths and/or filenames as needed.


Everyone seems to be missing the point.  It really doesn't matter where the MXD itself is stored.  The problem is the paths stored inside the MXD itself (or the shape files or whereever that path is stored) are pointing to the wrong location.  Back to my original question, I need to know how to update the paths that are shown in the attached image.
Reply
0 Kudos
Highlighted
Occasional Contributor III
Here is a link that should get you started, you'll probably need to change the type of workspaceFactory:

http://forums.esri.com/Thread.asp?c=93&f=992&t=107064
Reply
0 Kudos