Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error - when uploading excel file to server

Error - when uploading excel file to server

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Satish Developer
    wrote on last edited by
    #1

    Hi, i have done one application which tooks input as excel file which contains 2 columns. i took whole excel data to datatable and add two more columsn to datatable and export this data table to csv file by creating file programatically . The application is running sucessfully in my local machine. So i deployed in server. it working fine, when i logged into that server and run from there. If i run the deployed application from my local machine using http://192.168.1.110/Myapp/uploadfile.aspx. I am getting the following error. "The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data" (IF i took .xlsx file) "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."(IF i took .xls file) can any one say, why this error is occuring? I have given all permissons to the folder in server, where i creating the csv file.

    G. Satish

    L 1 Reply Last reply
    0
    • S Satish Developer

      Hi, i have done one application which tooks input as excel file which contains 2 columns. i took whole excel data to datatable and add two more columsn to datatable and export this data table to csv file by creating file programatically . The application is running sucessfully in my local machine. So i deployed in server. it working fine, when i logged into that server and run from there. If i run the deployed application from my local machine using http://192.168.1.110/Myapp/uploadfile.aspx. I am getting the following error. "The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data" (IF i took .xlsx file) "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."(IF i took .xls file) can any one say, why this error is occuring? I have given all permissons to the folder in server, where i creating the csv file.

      G. Satish

      L Offline
      L Offline
      l laxmikant
      wrote on last edited by
      #2

      check object which is doing operation on file has disposed before using it next time

      S 1 Reply Last reply
      0
      • L l laxmikant

        check object which is doing operation on file has disposed before using it next time

        S Offline
        S Offline
        Satish Developer
        wrote on last edited by
        #3

        ya, i have closed all the objects and connections related to this.

        G. Satish

        V 1 Reply Last reply
        0
        • S Satish Developer

          ya, i have closed all the objects and connections related to this.

          G. Satish

          V Offline
          V Offline
          VijayVishwakarma
          wrote on last edited by
          #4

          I think you have the file open and are trying to use that. Close the file and retry. Regards

          Vijay V. Yash Softech

          S 1 Reply Last reply
          0
          • V VijayVishwakarma

            I think you have the file open and are trying to use that. Close the file and retry. Regards

            Vijay V. Yash Softech

            S Offline
            S Offline
            Satish Developer
            wrote on last edited by
            #5

            My code is as follows. I am Getting error here... as "Excel Excep:The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data."

            public DataTable ReadingDatafromExcel()
            {
            DataTable dt = new DataTable();
            try
            {
            //Reading Data from Excel file to Data Table
            string FilePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
            string _filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string _attachpath = FileUpload1.PostedFile.FileName;
            string _fileexten = Path.GetExtension(FileUpload1.PostedFile.FileName);

                    string strConn = "";
            
                    if (\_fileexten == ".xls")
                    {
                        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                  "Data Source=" + \_attachpath + ";" +
                                  "Extended Properties=Excel 8.0;";
                    }
                    else if (\_fileexten == ".xlsx")
                    {
                        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                                  "Data Source=" + \_attachpath + ";" +
                                  "Extended Properties=Excel 12.0;";
                    }
            
                    OleDbConnection oledbconn = new OleDbConnection(strConn);
                    oledbconn.Close();
                    oledbconn.Open();
                    //You must use the $ after the object you reference in the spreadsheet
                    OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT \* FROM \[Sheet1$\]", oledbconn);
            
                    DataSet myDataSet = new DataSet();
                    
            
                    myCommand.Fill(myDataSet, "ExcelInfo");
                    dt = myDataSet.Tables\[0\];
                    oledbconn.Close();
                    myCommand.Dispose();
            
                    //Adding Columns to Data table
            
                    DataColumn dcGender = new DataColumn("Gender", System.Type.GetType("System.String"));
                    dt.Columns.Add(dcGender);
            
                    DataColumn dcCulture = new DataColumn("Culture", System.Type.GetType("System.String"));
                    dt.Columns.Add(dcCulture);
                    
                }
                catch (Exception dataex)
                {
                    Response.Write("Excel Excep:" + dataex.Message.ToString());
                }
                return dt;
            }
            

            G. Satish

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups