help to create app.config

  • Thread starter Vicky via DotNetMonster.com
  • Start date
V

Vicky via DotNetMonster.com

Hi,
Could anyone help me with some info how to create app.config file.
I need to put code of directory info in there, Thank you very much!

DirectoryInfo di = new DirectoryInfo("C:\\Vicky Development\\FundExplorer\\
Index\\Copy of IntlIndex");
---------------------------------------------------------------------

I know in app.config may like below
---------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>

<configuration>

<appSettings>

<!-- User application and configured property settings go here.-->

<!-- Example: <add key="settingName" value="settingValue"/> -->

<add key="reportingService.ServerName" value="Http://Localhost" />
<!-- No ending "/" -->

<add key="connOperations.ConnectionString" value="Integrated
Security=SSPI;Persist Security Info=False;Data Source=HIRST-IT1\
TEST;Initial Catalog=FundManager42205;" />

</appSettings>

</configuration>
------------------------------------------------------------------------
And in the code when I create Reader I do below

System.Configuration.AppSettingsReader appReader =

new System.Configuration.AppSettingsReader()
;

string connString = (string)appReader.GetValue(

"connOperations.ConnectionString",typeof
(string));

SqlConnection conn = new SqlConnection(connString);
------------------------------------------------------------------------

Here is begining part of the code
------------------------------------------------------------------
namespace dataReader

{

class Class1

{


[STAThread]

public static void Main(string[] args)

{

DirectoryInfo di = new DirectoryInfo("C:\\Vicky Development\\FundExplorer\\
Index\\Copy of IntlIndex");



// Get a reference to each file in that directory.

FileInfo[] fiArr = di.GetFiles();

int FundID=0;

int PeriodicityID = 0;;

string Ticker=null;

string currentLine = null;

//set up sql connection string

string myConnString= "workstation id=HIRST-IT1;packet size=4096;"+

"Integrated Security=SSPI;initial catalog=FundManager42205;"+ "Data
Source=HIRST-IT1\\TEST;"+

"persist security info=True";



// for each file in Directory, if TickerName match DB, load data

foreach (FileInfo fri in fiArr)

{

StreamReader sr = new StreamReader("C:\\Vicky Development\\FundExplorer\\
Index\\Copy of IntlIndex\\"+fri.Name);

//read the text file

//read the first row --header

currentLine = sr.ReadLine();

//read the second row contains data

currentLine = sr.ReadLine();

-
-
-
-
-
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

First of all you cannot write the app.config file, it's open with a write
lock for the application, that's why you cannot modify it in your code.

what you can do is create another file to store the config you need to
change in your code (you could also use the registry ) to do this you can
use a simpler var_name=value approach or another xml file with a similar
struct than the app.config file then read it and parse in your program.


I prefer to use the first approach though.

Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Vicky via DotNetMonster.com said:
Hi,
Could anyone help me with some info how to create app.config file.
I need to put code of directory info in there, Thank you very much!

DirectoryInfo di = new DirectoryInfo("C:\\Vicky
Development\\FundExplorer\\
Index\\Copy of IntlIndex");
---------------------------------------------------------------------

I know in app.config may like below
---------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>

<configuration>

<appSettings>

<!-- User application and configured property settings go
here.-->

<!-- Example: <add key="settingName" value="settingValue"/> -->

<add key="reportingService.ServerName" value="Http://Localhost" />
<!-- No ending "/" -->

<add key="connOperations.ConnectionString" value="Integrated
Security=SSPI;Persist Security Info=False;Data Source=HIRST-IT1\
TEST;Initial Catalog=FundManager42205;" />

</appSettings>

</configuration>
------------------------------------------------------------------------
And in the code when I create Reader I do below

System.Configuration.AppSettingsReader appReader =

new
System.Configuration.AppSettingsReader()
;

string connString = (string)appReader.GetValue(

"connOperations.ConnectionString",typeof
(string));

SqlConnection conn = new SqlConnection(connString);
------------------------------------------------------------------------

Here is begining part of the code
------------------------------------------------------------------
namespace dataReader

{

class Class1

{


[STAThread]

public static void Main(string[] args)

{

DirectoryInfo di = new DirectoryInfo("C:\\Vicky
Development\\FundExplorer\\
Index\\Copy of IntlIndex");



// Get a reference to each file in that directory.

FileInfo[] fiArr = di.GetFiles();

int FundID=0;

int PeriodicityID = 0;;

string Ticker=null;

string currentLine = null;

//set up sql connection string

string myConnString= "workstation id=HIRST-IT1;packet size=4096;"+

"Integrated Security=SSPI;initial catalog=FundManager42205;"+ "Data
Source=HIRST-IT1\\TEST;"+

"persist security info=True";



// for each file in Directory, if TickerName match DB, load data

foreach (FileInfo fri in fiArr)

{

StreamReader sr = new StreamReader("C:\\Vicky Development\\FundExplorer\\
Index\\Copy of IntlIndex\\"+fri.Name);

//read the text file

//read the first row --header

currentLine = sr.ReadLine();

//read the second row contains data

currentLine = sr.ReadLine();

-
-
-
-
-
}
 
V

Vicky via DotNetMonster.com

Ignacio,

Thank you so much fo your reply.
I try to understand you said "you cannot write the app.config file
it's open with a write lock for the application"

I did modify a app.config file before to a different server and DB,when I
did testing, I have to uncheck the Read only to make the changes.


But I will create a new file as you suggested.
I noticed that it is common to put server, and DB info in app.config file
I did not see an example to put Directory or file Path in app.config,
Do you have any example? I could give a try similiar like server, and DB
info. Thanks!

DirectoryInfo di = new DirectoryInfo("C:\\Vicky Development\\FundExplorer\\
Index\\Copy of IntlIndex");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top