Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to everybody.

I am using C#.net to convert Excel file to DataGrid for Client Request.

When I use the page to convert the excel to datagrid at localhost it works properly, but it will not work when I publish the site.

The error is
System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.

The code is

C#
protected void Upload_Click(object sender, EventArgs e)
        {
            try
            {
                strFileName = fleupForQuotation.PostedFile.FileName;
                if (strFileName.Trim() != "")
                {
                    string folderpath = "F://Upload//";
                    string attachedFile = fleupForQuotation.PostedFile.FileName;
                    if (Request.Browser.Browser == "IE")
                    {
                        fleupForQuotation.SaveAs(folderpath + fleupForQuotation.FileName);
                        strFileName = folderpath + fleupForQuotation.FileName;
                    }
                    else
                    {
                        fleupForQuotation.SaveAs(folderpath + attachedFile);
                        strFileName = folderpath + attachedFile;
                    }
                    hdnFileName.Value = strFileName;
                    

                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                SRCMError.ErrorLog(ex.ToString());
                SRCMError.ExceptionToEventLog(ex);
            }


            
            string ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=" + strFileName + ";" + "Extended Properties=Excel 8.0;";

            OleDbConnection conn = new OleDbConnection(ConnectionString);

            conn.Open();

            try
            {


                OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", conn);

                DataSet ds = new DataSet();

                oda.Fill(ds, "Details");

                grdExceltoGrid.DataSource = ds;

                grdExceltoGrid.DataBind();

            }

            catch (Exception ex)
            {

                Response.Write(ex.Message);

            }

            finally
            {

                conn.Close();

            }

        }

Please help me to solve this problem..

Thanks a lot
Posted
Updated 12-Jun-10 3:05am
v2
Comments
0x3c0 12-Jun-10 9:06am    
Thank you for your question; I've put your code in a code block so it's easier for other members to read

1 solution

Check if the account under which your application runs has right to access the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900