Hi all,
I have a site I've been on for a while. Users should be able to upload XML files. To get this done, I used the FileUpload control in vs2000 like this.
INPUT id="upload" type="file" runat="server">
I also added this code to bind that XML data in datagrid in the code-behind page:
conDB.Open()
Dim reportData As New DataSet()
strFileName = upload.PostedFile.FileName
'reportData.ReadXml(Server.MapPath(strFileName))
reportData.ReadXml(strFileName)
GridView1.DataSource = reportData
GridView1.DataBind()
conDB.Close()
The problem is when I try to do the upload a file(KPMCLT0001_shg_memberloan_Jan12.xml) from my local system, It give the error -
Could not find file "C:\WINDOWS\system32\KPMCLT0001_plf_memberwise_Jan12.xml".
Any idea Post solution For this post
Loading
Jignesh TrivediPosted Mar 19, 2012, 2:53 AM
uploaded file can not be use directly but you must store this file on web server before using it.
try this code
conDB.Open()
Dim reportData As New DataSet()
strFileName = upload.PostedFile.FileName
upload.PostedFile.SaveAs(Server.MapPath(strFileName))
reportData.ReadXml(Server.MapPath(strFileName))
GridView1.DataSource = reportData
GridView1.DataBind()
conDB.Close()
hope this help.
SenthilkumarPosted Mar 17, 2012, 5:25 AM
The code has some issues.
You cannot find the file full path. Some of the latest versions of browsers only support the full url and you do not have the permission to read the xml file from the client machine. Incase if you are uploading from the client server.
Always you need to upload the xml file into your local web server for any operations.
Here you have not stored the xml and only you are capturing the url of the xml file. If it is client and server are same machine then when you try to read the xml then it will look into where .net is installed.
Please try the following. It will work fine. I have tested.
If it is useful then mark it as "Accepted Answer"