Using the GDAL/OGR CSharp interface

Adding reference to the GDAL/OGR assemblies


Using the interface classes


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#

using System.Runtime.InteropServices;


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


string GDAL_HOME = @";C:\Program Files\FWTools\bin";  // for example

string path = Environment.GetEnvironmentVariable("PATH");
path += ";" + GDAL_HOME;
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

Last modified 12 years ago Last modified on Oct 24, 2007, 9:25:56 PM