I tried a lots on Google to find a sample of showing how to add a Field to attribute table of an existing shapefile. For example I have a Shapefile at


and need to add two field L_CITY and R_CITY both text and 50 characters limit. Can you please let me know how to do this in DotSpatial?

1 Answer 1


You would need to access the attribute table of the Shapefile, then get the column collection and add a new one:

static void AddColumn()
    string sf_name = @"C:\temp\a.shp";

    Shapefile sf = Shapefile.OpenFile(sf_name);

    //Create the new column (name + type)
    DataColumn newCol = new DataColumn("colName", typeof(string));
    //Add the length restriction
    newCol.MaxLength = 50;

    //Add the new column to the attribute table.

    // save in the current shapefile

    //Or save in a new one
    sf.SaveAs(@"C:\temp\a_copy.shp", true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.