How to upload the excel file to server?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varunkumarid
    New Member
    • Aug 2008
    • 40

    How to upload the excel file to server?

    Hi to everybody.

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

    When i using the page to convert the excel to datagrid at localhost it worked properly, but it will not work when i'm publish the site.

    The error is
    System.Data.Ole Db.OleDbExcepti on: 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

    Code:
    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();
    
                }
    
            }
    Last edited by Niheel; Jun 12 '10, 04:48 PM. Reason: please use code tags when posting code
Working...