wiki:GdalOgrCsharpUsage

Version 3 (modified by maphew, 17 years ago) ( diff )

how to modify local search path

Using the GDAL/OGR CSharp interface

Adding reference to the GDAL/OGR assemblies

TODO

Using the interface classes

TODO


Q & A

Modifying Local Search Path

Can I set a system path from C# that will be searched and that will not interfere with possible other processes search path?

If you want to add FWTools bin folder to PATH during run-time, so you don't have to pollute system PATH permanently, you can do it this way, in C#

DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool
   SetEnvironmentVariable(string lpName, string lpValue);

string path = Environment.GetEnvironmentVariable("PATH");
path += @";C:\Program Files\FWTools\bin";
SetEnvironmentVariable("PATH", path);

Now, for current process, all DLLs from FWTools package are accessible.

MSDN documentation:

Instead of the P/Invoke call to SetEnvironmentVariable, you can use C# native method Environment.SetEnvironmentVariable (AFAIR, available from .NET >= 2.0). Read the doc carefully, because there are two versions of this method. Unlike the Win32 API call accessed through P/Invoke, the method Environment.SetEnvironmentVariable has overloaded version that *may* change environment permanently, across processes.

adapted from http://lists.maptools.org/pipermail/gdal-dev/2007-August/013823.html

Note: See TracWiki for help on using the wiki.