Use Web.Config to store location of data file

Posted on 2011-05-10
Last Modified: 2012-05-11
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");
Question by:portalvale
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    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

    LVL 18

    Expert Comment

    LVL 27

    Expert Comment

    Set your web.config like this:

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

    In your code, you can then call:

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

    That's it.
    LVL 27

    Accepted Solution

    The <appSettings> element goes as a child to the <configuration> element.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
    The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Click on Too…
    The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now