can I get value from Web.config and use the value as a parameter?

in my orginal program code

 

     internal static void QueryForExportAgent(ref StringBuilder sb,decimal MasterKey)
     {
      sb.Append("SELECT * FROM ZT_Detail WHERE ");
      sb.Append(fMasterKey);
      sb.Append("=");
      sb.Append(setParametersValidation(MasterKey));
      sb.Append(" AND ");
      sb.Append(fTYPE);
      sb.Append("=");
      sb.Append(setParametersValidation("R"));
      sb.Append(" AND ");
      sb.Append(fPSEQ);
      sb.Append(">=");
      sb.Append(setParametersValidation(400000));
     }

 I want to use a "parameter" to instead of the 400000 of  setParametersValidation(400000)

and the parameter's value will from web.config.

 

in web.config , I add "<add key="SeqNo" value="400000" /> " after that , user can only modify the value in web.config and need not to modify orginal program code

my question is  how to get the value from web.config?  when get the value , could the value as a parameter return to another function? thank you

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
   <!-- PROD DATA -->
  <add key="AchDbConfig" value="server=CSAC_DBServer;uid=TestUser;pwd=TestUser;database=AchDM0902;Connect Timeout=30" />
  <add key="CioDbConfig" value="server=Framework_DBServer;uid=TestUser;pwd=TestUser;database=CIODD021;Connect Timeout=30" />
  <add key="FtpServer" value="128.1.2.3"/>
  <add key="FtpUser" value="AchUser@ctcbfrm@128.1.2.3" />
  <add key="FtpPassword" value="testpw" />
  <add key="AgentFolder" value="/data/server/ach/sk" />
  <add key="AgentInFile" value="skc111ej.dat" />
  <add key="AgentOutFile" value="skd616dj.dat" />
  <add key="AgentBankId" value="70-7A-0003" />

<add key="SeqNo" value="400000" />

  </appSettings>
</configuration>

 

---------------------------------

0
jcjcjc
8/6/2007 8:42:04 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
895 Views

Similar Articles

[PageSpeed] 5

Getting value from web.config:

 

string yourValue = System.Configuration.ConfigurationManager.AppSettings["SeqNo"];

 Passing to a method:
 

yourMethod (yourValue) //if it is an interger etc int.Parse it
 
0
addie
8/6/2007 9:01:06 AM

thank you addie

I have just found out this article about web.config

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=106

string conn = ConfigurationSettings.AppSettings["ORACLEConnectionString"];
OleDbConnection myConnection = new OleDbConnection(conn);
 
I was confused . 
in my folder have 2 Web Configuration File, one's name is CSACBATCH2.exe.config another is CSACImport2.exe.config
in this topic, when I mean "web.config" I mean the one named "CSACBATCH2.exe.config"
 if I want to use  "ConfigurationManager.AppSettings" do I need to point which web.config I want to use?
 
P.S. I'm using C# aspnet 1.0 
 
thank you
0
jcjcjc
8/6/2007 9:13:59 AM

Hi,

When ever you run your application from your IDE it will point to web.config file but if you run your CSACBATCH2.exe (By double clicking) then it will point to your CSACBATCH2.exe.config

Thanks,
Gaurang Majithiya


Dont forget to mark as an answer, if any post helped you.
0
gaurang_gr
8/6/2007 9:20:31 AM

still confused...

 in folder CSAC have a CASA.sln and 2 web configuration file( CSACBatch2.exe.config and CSACImport2.exe.config)  and a sub folder - CSAC

 in sub folder CSAC have  a Web configuration File named Web.config

 

what I'm modify is the web configuration file named CSACBatch2.exe.config

 

don't I need to modify or point something else to get value from CSACBatch2.exe.config?

if don't  how program know which web.config I'm calling?

thank you

0
jcjcjc
8/6/2007 10:11:22 AM

Hi

As I said, When ever you run your application from your IDE it will point to app.config file but if you run your CSACBATCH2.exe (By double clicking) then it will point to your CSACBATCH2.exe.config.

Note that the name of config file is same as the name of your exe file. So no need to modify or point any other config file.

If you rename or delete your CSACBatch2.exe.config file, then whenever you build your project it will generate new config file with the same name as exe file.

So if you double click on your exe (CSACBATCH2.exe) file, it will not call CSACImport2.exe.config or app.config, it will search for the same name CSACBATCH2.exe.config file.

Which config will call is depend on from which exe you are calling.

I think this scenario is only for windows application, not for web application.

Thanks,

Gaurang Majithiya


Dont forget to mark as an answer, if any post helped you.
0
gaurang_gr
8/6/2007 10:49:03 AM

sorry I still feel confused ...

what is the difference between xxx.exe.config, and xxx.config?

why .exe?

0
jcjcjc
8/8/2007 2:58:26 AM

I open a new webform for check if I really get value from Web.config like this

 

  private void Button1_Click(object sender, System.EventArgs e)
  {
   string StockValue = System.Configuration.ConfigurationSettings.AppSettings["SeqNo"];
   this.Label1.Text = StockValue;
  }

 after click button ,Label should appear the value I get from Web.config but just found out the value is null... why?

 

I want get add key="SeqNo" value from CSACBatch2.exe.config

 CSACBatch2.exe.config 's content like below

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
   <!-- PROD DATA -->
  <add key="AchDbConfig" value="server=CSAC_DBServer;uid=TestUser;pwd=TestUser;database=AchDM0902;Connect Timeout=30" />
  <add key="CioDbConfig" value="server=Framework_DBServer;uid=TestUser;pwd=TestUser;database=CIODD021;Connect Timeout=30" />
  <add key="FtpServer" value="128.1.2.3"/>
  <add key="FtpUser" value="AchUser@ctcbfrm@128.1.2.3" />
  <add key="FtpPassword" value="testpw" />
  <add key="AgentFolder" value="/data/server/ach/sk" />
  <add key="AgentInFile" value="skc111ej.dat" />
  <add key="AgentOutFile" value="skd616dj.dat" />
  <add key="AgentBankId" value="70-7A-0003" />

<add key="SeqNo" value="400000" />

  </appSettings>
</configuration>

0
jcjcjc
8/8/2007 6:18:05 AM

Hi Jcjcjc,

Based on my understanding, you want to access the data stored in the .config file. Now you cannot get the data from the .config file. If I have misunderstood you,  please feel free to let me know.

To better understand your issue, could you please confirm the following information:

  • If you want to get value from .config file in the web application by 'System.Configuration.ConfigurationSettings.AppSettings["SeqNo"]', the name of .config must be "Web.Config".


If you want to store data in the .config file and change this data without changing the code. I suggest you add your data into a XML file. You can read the data from this XML file in the application and also can change the data directly. And I think this won't confuse you again.

 

I hope this helps.

 


Thomas Sun
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Thomas
8/10/2007 3:51:50 AM
Reply:

Similar Artilces:

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Value property using FCKEditor in ATLAS is not updated, can't get Value
Hi,  I am using the ASP.NET integration of FCKEditor v2.2 inside an Atlas UpdatePanel.In a postback the editor's value is not updated and I can't get the value property of the control.  Is there any work around known?  Regards, HSHUeslei...

Get value of primary key after INSERT statement using Web Matrix (VB.NET)
I am using the following function developed using Web Matrix to insert a record into a table when the user clicks the submit button.  How can i get the "primary key" or value of the inserted record back to the application.  The following is my insert statement:Sub btnSubmit_Click(sender As Object, e As EventArgs)      CreateMyRecord("98", "UU1")       '==> need the primary key of the inserted record here.......End SubFunction CreateMyRecord(ByVal streetNumber As Integer, ByVal authorityRef As String) As Integer&nbs...

Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application
 Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application  please help me? Friend, Web.config has its own advantages. 1) Web.Config is used to store the important information like connections strings etc...so that it can be modified even after the code has been    deployed to the server without compiling the entire application again. 2) Since it is a XML file, there is no need of building the project of you are going to change the connection strings.   If you go for the class files,...

Getting values from my web.config
Is it possible to get the value in my web.config? for example I want to get the value of "Oraconn"...then I will post it to a textbox.text = Oraconn <connectionStrings> <add name="Oraconn" connectionString="Data Source=testdb;User ID=test;Password=test;Unicode=True" providerName="System.Data.OracleClient" /> <add name="PPCcon1" connectionString="Data Source=testme;Initial Catalog=YTMINVOICE;Persist Security Info=True;User ID=flt;Password=flt" providerName="System.Data.SqlClient" /> I notice notice in vb.net it uses app.config....is it also possible to get the values ...

problem with get value from textbox after get it value in load page
hi every one  i have problem with my web site when i get textbox value in load page   and Changed textbox the page do not take last value .   it take value in load page   this is code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)   TextBox1.Text = "aa" End SubProtected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox(TextBox1.Text) End Sub   when i press button message write "aa" while i changed the textbox   please if enyone knowen help me &nbs...

ObjectDataSource.SelectParameters
Hi All, I'm doing my custom paging control and I'd like to get exact parameter value of ODS, but this property is as not public. Is it possible to get this value not using reflection??? Many thanks Andrey labadiena: Hi All, I'm doing my custom paging control and I'd like to get exact parameter value of ODS, but this property is as not public. Is it possible to get this value not using reflection??? Many thanks Andrey In my opinion, I think it can't be done. But I suggest you also to ask this question in .NET Languages where you may get a better answer. Than...

How can I get a value from defined(third Value) from dropdownlist
I have a dropdown list and Query. query like this SELECT     ID, TypeTitle, TypeDef, definedFROM       Type I can get values from ID(first value) and TypeTitle(secord value)  when I select a item in the dropdown list using  functionPublic Sub DropDownList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList.SelectedIndexChanged How can I get a value from defined(third Value) from dropdownlist in same function Usually, you have DataTextField and DataValueField for a dropdownlis...

Get connection values from web.config
Hi everyone,I have the following problem:I'm using Crystal Reports (the ones included in VS2008) aspx.cs     protected void CrystalReportViewer1_Load1(object sender, EventArgs e)    {        ConfigureCrystalReports();    }    private void ConfigureCrystalReports()    {        report1 = new ReportDocument();        string reportPath = Server.MapPath("AverageOverwork.rpt");   &n...

How can I get and use value from WebService
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >Untitled Page "server"> "form1" runat="server"> "ScriptManager1" runat="server" EnablePageMethods="True"> "~/WebService3.asmx" InlineScript="...

How can you edit a Get Parameter value?
Is there any way to edit the value of a "get" parameter in the code behind without having to redirect the page to the same URL with the amended get parameters? E.G. if you navigate to the URL: page.aspx?x=1 Is there any way in the code behind (Page_Load method for example) to edit the value of x so that when the page loads the URL is: page.aspx?x=2 Thanks The querystring object is read-only so you will not be able to modify it without reloading the page. However, you could retrieve the value and store it as a variable and use the variable instead of the querystring...

How to Get a Value in the Web.Config File
In ASP.NET 2, C#, Web app, is there a way to get the value of an element in the Web.Config file. In this case, the value of the maxRequestLength parameter of the httpRuntime section of the web.config file. I want to test the size of a file selected for upload against this number so that I can put up an message if the user selects a file which is too big. Many thanks,Mike Thomas   try this:  HttpRuntimeSection section = System.Configuration.ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;if (section != null) &...

Query for substring to get some particular value in a string (Get querystring value by sql )
I have a column name URL in Table1 with data like  <a href="/Folder1/view_media_news.cfm?news_media_i=1">August 2002 Factsheet</a>            <a href="/Folder1/view_media_news.cfm?news_media_i=149">March 2002 Newsletter </a>  i need to grab the news_media_i value by sql query  Please any one can help me to get that particular value from string using substring or any other suggestion Thank you in advance SurendraIf this helps mark it as answer surendra_kla:i nee...

i can't get the value with <%=value%>
onclick="PopUp('SayfaKod-Yardim.aspx?<%=URL01%>')" a hyperlink has that property but i cant get the value by using this. it redirects the webpages to SayfaKod-Yardim.aspx?<%=...... so it give bad request error. Where is the problem ? it is not IN A DATAGRID OR A GRIDVIEW. it is placed normally =)    but i CAN  get  a value by using same method on a datagrid but using with #databinder.eval   well =) i can get with a normal html link but how to get the same value with the hyperlink ? damn there is no edit button on that forum =) <asp:Hy...

Web resources about - can I get value from Web.config and use the value as a parameter? - asp.net.getting-started

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google Webmaster Tools Parameter Handling - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 11/25/2015 3:53:20 PM