Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:32:02+00:00 2026-06-02T03:32:02+00:00

I need to programmatically open an Excel file that is stored in a MOSS

  • 0

I need to programmatically open an Excel file that is stored in a MOSS 2007 Shared Documents List. I’d like to use an OleDbConnection so that I may return the contents of the file as a DataTable. I believe this is possile since a number of articles on the Web imply this is possible. Currently my code fails when trying to initialize a new connection (oledbConn = new OleDbConnection(_connStringName); The error message is:

Format of the initialization string does not conform to specification starting at index 0.

I believe I am just not able to figure the right path to the file. Here is my code:

        public DataTable GetData(string fileName, string workSheetName, string filePath)
    {   
// filePath == C:\inetpub\wwwroot\wss\VirtualDirectories\80\MySpWebAppName\Shared Documents\FY12_FHP_SPREADSHEET.xlsx
            // Initialize global vars
        _connStringName = DataSource.Conn_Excel(fileName, filePath).ToString();
        _workSheetName = workSheetName;
        dt = new DataTable();
        //Create the connection object
        if (!string.IsNullOrEmpty(_connStringName))
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                oledbConn = new OleDbConnection(_connStringName);

                try
                {

                    oledbConn.Open();
                    //Create OleDbCommand obj and select data from worksheet GrandTotals
                    OleDbCommand cmd = new OleDbCommand("SELECT * FROM " + _workSheetName + ";", oledbConn);

                    //create new OleDbDataAdapter
                    OleDbDataAdapter oleda = new OleDbDataAdapter();
                    oleda.SelectCommand = cmd;
                    oleda.Fill(dt);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
                finally
                {
                    oledbConn.Close();
                }
            });
        }
        return dt;
    }

        public static OleDbConnection Conn_Excel(string ExcelFileName, string filePath)
    {
// filePath == C:\inetpub\wwwroot\wss\VirtualDirectories\80\MySpWebAppName\Shared Documents\FY12_FHP_SPREADSHEET.xlsx
OleDbConnection myConn = new OleDbConnection();
        myConn.ConnectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0");
        return myConn;
    }

What am I doing wrong, or is there a better way to get the Excel file contents as a DataTable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:32:04+00:00Added an answer on June 2, 2026 at 3:32 am

    I ended up using the open source project Excel Data Reader

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to open up an excel file, do I need any special references? I want
I am trying to open an InfoPath 2007 file programmatically from a Windows service,
I need to unzip file synced through itunes in the documents directory programmatically. There
I need to be able to update my config file programmatically and change my
I need to programmatically insert a row into an Excel Spreadsheet multiple times. I
I need to be able to generate dependency diagrams programmatically. I'd like it to
I have an VB.Net/C# application that programmatically: Creates an RTF document Open it up
I'm using xmlhttp via vba in excel 2010. I need to programmatically add an
the question is how to open Run programmatically from c++? I know that have
Interop.Excel version 12 Office Excel 2007 I have worked on code to open .xslm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.