向圖層新增欄位
/// <summary>
/// 向圖層新增欄位
/// </summary>
/// <param name="layer">圖層物件</param>
/// <param name="name">欄位名稱</param>
/// <param name="alias">欄位別名</param>
/// <param name="type">欄位型別</param>
public static void AddField(ILayer layer, string name, string alias, esriFieldType type)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = (IFeatureLayer)layer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向圖層新增欄位
/// </summary>
/// <param name="layer">圖層物件</param>
/// <param name="name">欄位名稱</param>
/// <param name="alias">欄位別名</param>
/// <param name="type">欄位型別</param>
/// <param name="length">欄位長度</param>
public static void AddField(ILayer layer, string name, string alias, esriFieldType type, int length)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = (IFeatureLayer)layer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fieldEdit.Length_2 = length;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向圖層新增欄位
/// </summary>
/// <param name="featureLayer">圖層物件</param>
/// <param name="name">欄位名稱</param>
/// <param name="alias">欄位別名</param>
/// <param name="type">欄位型別</param>
public static void AddField(IFeatureLayer featureLayer, string name, string alias, esriFieldType type)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = featureLayer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向圖層新增欄位
/// </summary>
/// <param name="featureLayer">圖層物件</param>
/// <param name="name">欄位名稱</param>
/// <param name="alias">欄位別名</param>
/// <param name="type">欄位型別</param>
/// <param name="length">欄位長度</param>
public static void AddField(IFeatureLayer featureLayer, string name, string alias, esriFieldType type, int length)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = featureLayer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fieldEdit.Length_2 = length;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}