2017-02-03 111 views
0

我目前正在嘗試使用C#Web API從Kentico中提取數據,並且我可以成功提取數據,但我也計劃將其存儲到數據庫中。GET API請求 - 表單數據類型

使用調用,比如:/rest/bizformitem.bizform.contactus

我收到回所有的表單中的數據,但由於我這些值存儲到數據庫中,我想知道這種形式的名稱/值的字段的數據類型。

大多數API參考文獻都有列表,例如:ID:USER_ID | Type:int | Desc:User ID Form Field

我想通過API或文檔爲表單中的這些值找到一個參考,所以任何援助將不勝感激。

回答

1

您需要查看CMS_Class數據庫表。找到你的類,然後是ClassFormDefinition字段,它具有顯示所有類型的字段的XML。

加載XML成的XmlDocument,則//字段[@柱= 「YourColumnName」]的selectNodes,下面是XML

<field column="CultureName" visible="true" columntype="text" fieldtype="CustomUserControl" system="true" columnsize="200" publicfield="false" guid="7b7c2f84-da09-4874-aade-a4d3b77b975d"> 

現在請注意的樣本,所述columntype是那種Kentico特定的命名,所以你必須做一個開關將其轉換爲.Net類或SQL數據庫。

switch (fieldType) 
     { 
      case "longtext": 
      case "text": 
      default: 
       dt.Columns.Add(fieldName, typeof(string)); 
       break; 
      case "binary": 
       dt.Columns.Add(fieldName, typeof(byte[])); 
       break; 
      case "boolean": 
       dt.Columns.Add(fieldName, typeof(Boolean)); 
       break; 
      case "date": 
       dt.Columns.Add(fieldName, typeof(DateTime)); 
       break; 
      case "datetime": 
       dt.Columns.Add(fieldName, typeof(DateTime)); 
       break; 
      case "decimal": 
       dt.Columns.Add(fieldName, typeof(Decimal)); 
       break; 
      case "double": 
       dt.Columns.Add(fieldName, typeof(Double)); 
       break; 
      case "integer": 
       dt.Columns.Add(fieldName, typeof(Int32)); 
       break; 
      case "longinteger": 
       dt.Columns.Add(fieldName, typeof(Int64)); 
       break; 
      case "timespan": 
       dt.Columns.Add(fieldName, typeof(TimeSpan)); 
       break; 
      case "guid": 
       dt.Columns.Add(fieldName, typeof(Guid)); 
       break; 
     } 
+0

是否可以通過REST API訪問CMS_Class數據庫表? – confusedandamused

+0

是的,你可以通過'/ rest/cms.class/all'獲取數據 – rocky

+0

@rocky當試圖使用/rest/cms.form/all或者/ rest/cms.class/all時, 403錯誤? – confusedandamused