Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, all my friends..You all are a constant source of support and help.
I wanted to bind my xml with telerik reporting and then convert it to pdf file. in the morning i was able to bind the xml but now its not working..
i have written the code below. but in the variable stream i am not getting value. My xml is in the project.web and there in the clientbin folder.Pls help me

C#
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("FirstSilverlightApplication.Web.ClientBin.Data.xml");
var xml = XDocument.Load(new StreamReader(stream));

// Query the XML data
var x  = from r in xml.Descendants("Student")
               select new Student
               {
                   SName = (string)r.Attribute("Name").Value,
                   RollNumber = (string)r.Attribute("RollNumber").Value,
               };
(sender as Telerik.Reporting.Processing.Report).DataSource = x.ToList<Student>();




Thanks in advance.
Posted
Updated 31-May-11 0:16am
v3

To solve the second part of your question:

Try to get the xml in this way:
I am not sure about your folder structure, but here my XML is inside the Resources Folder.
C#
Stream stream = Application.GetResourceStream(new Uri("Resources/XMLFile1.xml", UriKind.RelativeOrAbsolute)).Stream;
StreamReader reader = new StreamReader(stream);
// Parse it
XDocument xDoc = XDocument.Parse(reader.ReadToEnd());

Also try not to use "var" types. For ex: XDocument.Load() function will always return XDocument type only.

Update:
Assembly can also be used, an Example:

here WpfApplication2 is the namespace, Resources is the Folder name.
C#
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("WpfApplication2.Resources.XMLFile1.xml");
StreamReader reader = new StreamReader(stream);
XDocument xDoc = XDocument.Parse(reader.ReadToEnd());


But the catch is, your XML should be an "Embedded Resource" instead of simple Resource. Otherwise the stream will be null.
For more reading, you can check out this link: http://www.silverlightexamples.net/post/How-to-Get-Files-From-Resources-in-Silverlight-20.aspx[^]

Hope it helped.
 
Share this answer
 
v4
Comments
Saumya J Pandey 31-May-11 6:59am    
thanks tarun, but what is this GetResourceStream ? um having an error sayin no definition.
Tarun.K.S 31-May-11 7:04am    
Uh then I think Silverlight doesn't have this. Actually I tried in WPF application. Anyway I will be right back with another solution.
Saumya J Pandey 31-May-11 7:05am    
thanks a ton tarun..
Tarun.K.S 31-May-11 7:20am    
I have updated the answer. It's better to use Application.GetResourceStream as it can handle simple "Resource" files but don't know why its giving an error for you.
Saumya J Pandey 31-May-11 7:30am    
thanks for the help Tarun but i am getting a null in stream
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900