cancel
Showing results for 
Search instead for 
Did you mean: 

Load from xml CSharp

Former Member
0 Kudos

Hi all,

I'm trying to write some code in C# and I have a problem with LoadFromXML function. Here's my code:

try

{

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

string path;

string refString;

path = Environment.CurrentDirectory;

<b>xmlDoc.LoadXml(path + "
" + fileName); //Exception</b>

refString = xmlDoc.InnerXml;

App.LoadBatchActions(ref refString);

}

catch (Exception ex)

{

Msg("Load from XML failed: " + ex.Message);

}

In bolded line ecpetion appears: "The data at the root level is invalid. Line 1, position 1." . Does anyone know what to do with this?

Regards

Hmg

Accepted Solutions (1)

Accepted Solutions (1)

rasmuswulff_jensen
Active Contributor
0 Kudos

The LoadXml method takes in a string of xml-data... Try using the Load method instead that accepts a filename


XmlDataDocument x = new XmlDataDocument();
x.Load(xmlPath);
string xml = x.InnerXml;

Message was edited by:

Rasmus Jensen

Former Member
0 Kudos

Thanks Rasmus. Now it works.

Regards,

Hmg

Answers (3)

Answers (3)

Former Member
0 Kudos

hi friend,

i read your code. Tell which type of exception u are getting.

if it is filenotfound exception, make sure that your file is saved in folder bin->debug of your project.

Hope this will help you..

regards

nirdesh

Former Member
0 Kudos

I will suggest you that your XML files should be Embedbed Resource of Assembly

& try to get xml from that embedded file....

rasmuswulff_jensen
Active Contributor
0 Kudos

Also instead of

Enviroment.CurrentDirectory

you should use

System.Windows.Forms.Application.StartupPath

, because after you build you add-on with an installer Enviroment.CurrentDirectory does not point to the installed folder