Search code examples
c#c#-4.0geoserver

Copying with c# in geoserver


Anybody knows about documentation or examples that how copy files (workspaces,shapes,..) in geoserver usinG C#?


Solution

  • This C# code will create a new workspace on GeoServer.

    using System;
    using System.Net;
    using System.IO;
    
    ...
    
    string url = "http://localhost:8080/geoserver/rest/workspaces";
    WebRequest request = WebRequest.Create(url);
    
    request.ContentType = "text/xml";
    request.Method = "POST";
    request.Credentials = new NetworkCredential("admin", "geoserver");
    
    byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes("<workspace><name>my_workspace</name></workspace>");
    Stream reqstr = request.GetRequestStream();
    reqstr.Write(buffer, 0, buffer.Length);
    reqstr.Close();
    
    WebResponse response = request.GetResponse();
    
    ...
    

    GeoServer has examples on how to do create workspaces, stores, layers and styles using cURL: GeoServer cURL REST Configuration Examples. Then you can convert the cURL examples using the code above.