We help IT Professionals succeed at work.
Get Started

Add List<newFiles> to a dt, save to table_1

Last Modified: 2015-03-08
In this code, I need help with two items:

Q1: How to code this:        // define a datatable (dt) and add newFiles List to it , see the code below.

Q2: Given cs, cn, table_1, how to do ...       // add dt to SQL Server table_1

   protected void Button1_Click(object sender, EventArgs e)
        List<ExcelFiles> newFiles = new List<ExcelFiles>();
        ExcelFiles xlFile = new ExcelFiles();

        // Put file names in the directory into array.
        string dirPath ="C:\\Users\\Mike\\Data\\"; 
        var files = Directory
                        .EnumerateFiles(dirPath, "*", SearchOption.TopDirectoryOnly)

        // store file names in xlFile object
        foreach (string name in files)
            string file =name;
            string fileExtention = name.Substring(name.Length - 5);
            if (fileExtention == ".xlsx")
                xlFile.filename = file;

                // add file name to xlFile object 
        // define a datatable (dt) and add newFiles List to it (I will need this method elsewhere as well)

       // add dt to SQL Server table_1

Open in new window

Watch Question
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE