Problem to Read an XML file

scalf

Freshman
Joined
Jun 15, 2004
Messages
25
Location
FRANCE
Hello everybody,

Does someone have a piece of code to read an XML file as the one I put in attachment of this post ?

I want to import it in a Sharepoint list and I have developped a webpart which creates the list and I'm blocking on the way I can read the file to create the names of columns and get the data of each column. If you want to know what I want to get, read the XML file in Excel.

NB : I sent the file in txt so that you can read it first and notice that there is no malicious code in it.

Thank you all.
 

Attachments

I can't say I know a thing about asp.Net, but using c# its simply a case of something along the lines of this...

C#:
string sTitle = "";

while(myReader.Read())
{
	if(myReader.NodeType == System.Xml.XmlNodeType.Element)
	{
		if(myReader.Name == "Title")
		{
                        sTitle = myReader.ReadInnerXml();
                }
        }
}
Using this method you check for the main node of each item, then create the row. Then cycle through each property to read in the column information.

I'm not sure if this helps you, but I hope it does.
 
It goes but...

Thanks, that's more less what I started to do. The problem I have is that the file path which is indicated using an HTML input file textbox is not accepted by Sharepoint Server and it seems that it cannot read the value in it (perhaps for security reasons or maybe because I'm not using the right function).
I use MyHtmlInputFile.value (where MyHtmlInputFile is the name of the input file control) to get the path of the file...I've tried to use the Server.MapPath but the webpart components seem to not recognize this type of method...
redface.gif


Any ideas ?
 
Last edited:
Hmm.. Just noticed I neglected to mention the fact I would use the XmlTextReader class (myReader = new XmlTextReader), I'm assuming this is accessible through Asp.
 
Security pbs

I succeed in getting the value which is in the html input file control but It seems that for security reasons Sharepoint refuses to read the file. Are there solutions to make a local file readable by a server ?

NB : I tried to put my file in a shared folder on my computer and to put read rights for All users, but I've always the same FileIOPermission error.
 
I got what I was looking for...it can help others ;-)

Here is what I did :

MyHTMLinputFile.PostedFile.SaveAs("C:\Mypath\Myfile.ext")

Of course, C:\Mypath\Myfile.ext" is the path and file ON THE DESTINATION SERVER (I personnaly published the file in a subdirectory of my Inetpub/wwwroot/Mysite)

Regards.
 
Back
Top