[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

Use Web.Config to store location of data file

Please help with an example of web.config to store location of data file             GridView1.DataSource = GetDataTable(@"\\server1\fans.txt");
 
I'd like to store \\server1\fans.txt on the web.config

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
            GridView1.DataSource = GetDataTable(@"\\server1\fans.csv");
            GridView1.DataBind();
        }
    }
0
portalvale
Asked:
portalvale
  • 2
1 Solution
 
käµfm³d 👽Commented:
Right-click your project file and go to Project settings. On the settings tab, add a new property (name it whatever you like). Then in code, you can do something like this:
GridView1.DataSource = GetDataTable(Properties.Settings.Default.NewSettingName);

Open in new window

0
 
dj_alikCommented:
0
 
nmarunCommented:
Set your web.config like this:

<appSettings>
   <add key="fileLocation" value="\\server1\fans.csv" />
</appSettings>

In your code, you can then call:

string fileLocation = WebConfigurationManager.AppSettings["fileLocation"];
GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
GridView1.DataSource = GetDataTable(fileLocation);
GridView1.DataBind();

That's it.
Arun
0
 
nmarunCommented:
The <appSettings> element goes as a child to the <configuration> element.

Arun
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now