{"id":795,"date":"2023-01-24T08:47:06","date_gmt":"2023-01-24T08:47:06","guid":{"rendered":"https:\/\/turtleflyblog.com\/?p=795"},"modified":"2023-01-24T08:50:25","modified_gmt":"2023-01-24T08:50:25","slug":"extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file","status":"publish","type":"post","link":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/","title":{"rendered":"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file"},"content":{"rendered":"\n

When a programmer writes code, he or she doesn\u2019t want to have every specific custom data and settings in the code. Instead, they want to have those written in a configuration file. This article will introduce how to set an object list in .Net Framework App.config and .Net Core Appsetting.json respectively and also how to extract those data from a configuration file.<\/p>\n\n\n\n

.Net Core<\/strong><\/p>\n\n\n\n

appsettings.json<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

The diagram above shows how to write EmailList<\/strong> object list inside appsetting.json with ToEmails<\/strong> array. In order to extra a list object data from appsetting.json, you need to download these packages.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Create a class EmailSetting<\/strong> which matches to the Email array data structure.<\/p>\n\n\n\n

The main program(Program.cs)<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Firstly, set the JSON file\u2019s name and its path<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Then we need to decide which section of the JSON file you want to extract. This article will parse the Object EmailList <\/strong>with its ToEmails<\/strong> array.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

To print all the data from the array EmailSetting<\/strong>., the print output result is shown below.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

.NET Framework<\/strong><\/p>\n\n\n\n

App.config<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

After setting the email array inside App.config, you need to parse the XML structure of App.config. emailSettings<\/strong> has two properties address<\/strong> and displayName<\/strong>, we need to be able to parse these two properties\u2019 value. The diagram provided below shows how to parse XML structure with emailList list object<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

The above figure will crawl the tree structure of the XML file. When the XML node attribute name is the same as the emailSetting attribute name, it will be added to the myConfigObject(EmailSetting) collection.<\/p>\n\n\n\n

EmailSetting<\/strong> object<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Program.cs<\/p>\n\n\n\n

Parse App.config and prints out Email array values<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

It is better to set important settings and data in a configuration file as this helps developers to customize the settings based on different environments. Knowing how to write and extra complex data structures in App.config(.Net Framework) or appsettings.json (Net Core), this will give .Net developers one more choice when dealing with localization data and settings<\/p>\n","protected":false},"excerpt":{"rendered":"

When a programmer writes code, he or she doesn\u2019t want to have every specific custom data and settings in the code. Instead, they want to have those written in a configuration file. This article will introduce how to set an object list in .Net Framework App.config and .Net Core Appsetting.json respectively and also how to […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-795","post","type-post","status-publish","format-standard","hentry","category-programming-2"],"yoast_head":"\nExtract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly\" \/>\n<meta property=\"og:description\" content=\"When a programmer writes code, he or she doesn\u2019t want to have every specific custom data and settings in the code. Instead, they want to have those written in a configuration file. This article will introduce how to set an object list in .Net Framework App.config and .Net Core Appsetting.json respectively and also how to […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Who said turtle cannot fly\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-24T08:47:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-24T08:50:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png\" \/>\n<meta name=\"author\" content=\"Joseph\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/\",\"url\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/\",\"name\":\"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly\",\"isPartOf\":{\"@id\":\"https:\/\/turtleflyblog.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png\",\"datePublished\":\"2023-01-24T08:47:06+00:00\",\"dateModified\":\"2023-01-24T08:50:25+00:00\",\"author\":{\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\"},\"breadcrumb\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#breadcrumb\"},\"inLanguage\":\"en-AU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png?fit=554%2C493&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png?fit=554%2C493&ssl=1\",\"width\":554,\"height\":493},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/turtleflyblog.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/turtleflyblog.com\/#website\",\"url\":\"https:\/\/turtleflyblog.com\/\",\"name\":\"Who said turtle cannot fly\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/turtleflyblog.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-AU\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\",\"name\":\"Joseph\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"caption\":\"Joseph\"},\"sameAs\":[\"https:\/\/turtleflyblog.com\/\/\"],\"url\":\"https:\/\/turtleflyblog.com\/author\/joseph\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/","og_locale":"en_US","og_type":"article","og_title":"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly","og_description":"When a programmer writes code, he or she doesn\u2019t want to have every specific custom data and settings in the code. Instead, they want to have those written in a configuration file. This article will introduce how to set an object list in .Net Framework App.config and .Net Core Appsetting.json respectively and also how to […]","og_url":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/","og_site_name":"Who said turtle cannot fly","article_published_time":"2023-01-24T08:47:06+00:00","article_modified_time":"2023-01-24T08:50:25+00:00","og_image":[{"url":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png","type":"","width":"","height":""}],"author":"Joseph","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joseph","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/","url":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/","name":"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file - Who said turtle cannot fly","isPartOf":{"@id":"https:\/\/turtleflyblog.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage"},"image":{"@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage"},"thumbnailUrl":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png","datePublished":"2023-01-24T08:47:06+00:00","dateModified":"2023-01-24T08:50:25+00:00","author":{"@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172"},"breadcrumb":{"@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#breadcrumb"},"inLanguage":"en-AU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#primaryimage","url":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png?fit=554%2C493&ssl=1","contentUrl":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2023\/01\/1.png?fit=554%2C493&ssl=1","width":554,"height":493},{"@type":"BreadcrumbList","@id":"https:\/\/turtleflyblog.com\/en\/2023\/01\/24\/extract-list-or-array-data-from-net-framework-appconfig-or-net-core-appsetting-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/turtleflyblog.com\/en\/"},{"@type":"ListItem","position":2,"name":"Extract List or Array data from .NET Framework AppConfig or .NET Core AppSetting file"}]},{"@type":"WebSite","@id":"https:\/\/turtleflyblog.com\/#website","url":"https:\/\/turtleflyblog.com\/","name":"Who said turtle cannot fly","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/turtleflyblog.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-AU"},{"@type":"Person","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172","name":"Joseph","image":{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","caption":"Joseph"},"sameAs":["https:\/\/turtleflyblog.com\/\/"],"url":"https:\/\/turtleflyblog.com\/author\/joseph\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/comments?post=795"}],"version-history":[{"count":2,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/795\/revisions"}],"predecessor-version":[{"id":812,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/795\/revisions\/812"}],"wp:attachment":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/media?parent=795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/categories?post=795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/tags?post=795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}