Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

defaultconnection appsettings.json

  {
    "ConnectionStrings": {       
      "DefaultConnection": "Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true"        
    } 
  }
Comment

.net core read configuration from appsettings.json

var AppName = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["APP_Name"];
Comment

use appsettings.json in console app

All that’s required is to add the following NuGet packages and an appsettings.json file.

Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json

The appsettings.json files “Copy to Output Directory” property should also be set to “Copy if newer” so that the application is able to access it when published.
Comment

get appsettings from app.config c# .net core

"AssetsFolder": {
    "UserFolder": "/assets/images/Users/",
    "EventFolder": "/assets/images/Events/",
    "CoursesFolder": "/assets/images/Courses/",
    "filesFolder": "/assets/images/files/"
  },

string pathUser = _configuration["AssetsFolder:UserFolder"].ToString();
Comment

create appsettings.json inno setup

[Code]

#include "JsonParser.pas"

function FindJsonValue(
  Output: TJsonParserOutput; Parent: TJsonObject; Key: TJsonString;
  var Value: TJsonValue): Boolean;
var
  I: Integer;
begin
  for I := 0 to Length(Parent) - 1 do
  begin
    if Parent[I].Key = Key then
    begin
      Value := Parent[I].Value;
      Result := True;
      Exit;
    end;
  end;

  Result := False;
end;

function FindJsonArray(
  Output: TJsonParserOutput; Parent: TJsonObject; Key: TJsonString;
  var Arr: TJsonArray): Boolean;
var
  JsonValue: TJsonValue;
begin
  Result :=
    FindJsonValue(Output, Parent, Key, JsonValue) and
    (JsonValue.Kind = JVKArray);

  if Result then
  begin
    Arr := Output.Arrays[JsonValue.Index];
  end;
end;

{ ... }

var
  JsonLines: TStringList;
  JsonParser: TJsonParser;
  LaunchSettingsArray: TJsonArray;
  ToolDirectoryValue: TJsonValue;
  I: Integer;
begin
  { ... }

  JsonLines := TStringList.Create;
  JsonLines.LoadFromFile(FileName);

  ParseJson(JsonParser, JsonLines.Text);

  if Length(JsonParser.Output.Errors) > 0 then
  begin
    Log('Error parsing JSON');
    for I := 0 to Length(JsonParser.Output.Errors) - 1 do
    begin
      Log(JsonParser.Output.Errors[I]);
    end;
  end
    else
  begin
    if FindJsonArray(
         JsonParser.Output, JsonParser.Output.Objects[0],
         'launchSettings', LaunchSettingsArray) and
       (GetArrayLength(LaunchSettingsArray) >= 0) and
       (LaunchSettingsArray[0].Kind = JVKObject) and 
       FindJsonValue(
         JsonParser.Output,
         JsonParser.Output.Objects[LaunchSettingsArray[0].Index], 'toolDirectory',
         ToolDirectoryValue) and
       (ToolDirectoryValue.Kind = JVKString) then
    begin
      Log(Format(
        'launchSettings[0]:toolDirectory:%s', [
        JsonParser.Output.Strings[ToolDirectoryValue.Index]]));
      JsonParser.Output.Strings[ToolDirectoryValue.Index] := 'Test';
      JsonLines.Clear;
      PrintJsonParserOutput(JsonParser.Output, JsonLines);
      JsonLines.SaveToFile(FileName);
    end;
  end;

  ClearJsonParser(JsonParser);
  JsonLines.Free;
end;
Comment

PREVIOUS NEXT
Code Example
Csharp :: params string[] 
Csharp :: how to show enum name list from input in swagger c# 
Csharp :: how to get text color alpha unity 
Csharp :: how to know if object with a certain tag exists unity c# 
Csharp :: epplus how to align text to right 
Csharp :: asp.net core get current culture in controller 
Csharp :: asp net identity extend relationship 
Csharp :: best unity regex for email validation in c# 
Csharp :: convert excel to datatable using epplus 
Csharp :: creating an object 
Csharp :: unity phone vibration 
Csharp :: flutter find a widget 
Csharp :: c# remove numericUpDown white space 
Csharp :: backcolor app winform C3 
Csharp :: c# how to return 2 strings 
Csharp :: DataTable GetErrors 
Csharp :: C# Rev.ai transcription 
Csharp :: how to make game restart when player touches a object unity 
Csharp :: how to refrence a variable from other script in c# 
Csharp :: wpf change the content of the button wait 5 secound and then change it again 
Csharp :: how to disable scale anti-aliasing in monogame 
Csharp :: C# walk down a tree and back 
Csharp :: how to start commvault services on linux 
Csharp :: class combining 
Csharp :: c# return propertty from each object in object lpist 
Csharp :: C# Move Camera Over Terrain Using Touch Input In Unity 3D - Append To Camera 
Csharp :: unity check if transform doent have parent 
Csharp :: c# open folder in explorer zugriff verweigert 
Csharp :: check that IEnumerable is not empty 
Csharp :: c# summary angle brackets 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =