472,374 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

import excel file

49
i want to import excel file to gridview but there was error(Failed to map this path "/xmltest.xml") and i couldn't handle it my code:
Expand|Select|Wrap|Line Numbers
  1. public void fillGrid()
  2.     {
  3.         DataSet ds = new DataSet();
  4.         ds.ReadXml(Server.MapPath("../xmltest.xml"));
  5.         GridView1.DataSource = ds;
  6.         GridView1.DataBind();
  7.     }
  8.     protected void Page_Load(object sender, EventArgs e)
  9.     {
  10.         if (!IsPostBack)
  11.         {
  12.             fillGrid();
  13.         }
  14.     }
  15.  
  16.     protected void btImport_Click(object sender, EventArgs e)
  17.     {
  18.         string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" + ("Data Source=C:\\WebSqlEditor\\Test.xls;" + "Extended Properties=\"Excel 8.0;\"")); 
  19.         string SSQL = "SELECT name , dept, salary  from [sheet1$]";
  20.         OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn); 
  21.         DataSet ds = new DataSet();
  22.         oleDA.TableMappings.Add("Table","ExcelTest"); 
  23.         oleDA.Fill(ds);
  24.         GridView1.DataSource = ds.Tables[0].DefaultView; 
  25.         GridView1.DataBind();
  26.     }
i need any idea to fix this error,i tried more to fix it but i cann't
thanks
Mar 20 '09 #1
4 2668
Plater
7,872 Expert 4TB
Does the xmltest.xml file exist in the parent directory of wherever you are?
You should try outputing the result of Server.Mappath, to see what its returning (if anything at all)

Also I think that if you try to go to directory higher up then the "root" directory for your webapplication, it will fail
Mar 20 '09 #2
orked
49
i made the source of excel file in c:websqleditor
in this folder i made excel file called(test) as i wrote in code
note if i changed the path the same error appear
i wonder if i need any thing to map path
Mar 20 '09 #3
Plater
7,872 Expert 4TB
Well by default your webpage would be in like c:\inetpub\wwwroot\
So running Server.MapPath("../xmltest.xml"); Would produce c:\inetpub\xmltext.xml
Which would be above the "root" of your web application, and thus the server.mappath call would error because you are trying to access a file outside of its dominion
Mar 20 '09 #4
orked
49
at first my application wasn't in the root c:\Inetpub\wwwroot\.....
i put it in this root and i changed the path in my code to be suitable for path but the error still appear
Mar 20 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
1
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
1
by: baling | last post by:
Hi.... Hi everybody, i have a code that i make in VBA and know I want to use this code in to VB6. But i don't know how to use that code in to VB 6.0 Please correct this code so i can use it in VB...
8
by: shenkel55 | last post by:
I'm using Access and Excel 2003. Using either the import wizard or code, I have the same problem. This problem only happens with Excel files automatically generated by Corp IT. If I try to do an...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.