views:

176

answers:

3

Hello..

I am very new to Silverlight development. I understand that this is client side technology therefore the paradyme is differant from that of conventional ASP.NET development. Having said that, I don't understand where my server side code is deployed.

I have a silver light \ MVC application. I am trying to read an XML document from within my 'Models' folder. The following peice of code is executed from within a class that is in the same location as the XML document, 'Models'. The load() results in a SystemIOFileNotFound exception. I noticed that when building the application the XML document is not laid down in the same location as the web project's assembly. I assume this is specific to the fact that this is a Silverlight project. Can someone tell me what I'm missing?

  _xdoc = new XDocument();
   _xdoc = XDocument.Load(new Uri("videos.xml",UriKind.Relative).ToString());

Edit..

The behavior I am after is the start page (silverlight) populates controls via a server side controller. ie localhost/video

A: 

Silverlight can't access your filesystem (thankfully), which is why you can't access the file. Try embedding it as a resource, or storing it in the local storage API provided by silverlight.

Pierreten
A: 

Assuming that your Models folder is in the Web project (i.e. not the Silverlight project), I think that your problem is unrelated to Silverlight. The code loading the XML file assumes that the file is in the current directory, so you need to ensure this through your deployment technique.

If you are doing this in the Silverlight part, you should put the XML file in an embedded resource and access it as a stream (get it with Assembly.GetManifestResourceStream) or as a resource (a la WPF, not an embedded resource) and access it with the package part syntax.

Timores
You're right it is in my web project. However the above code seems to look for the XML doc in my c:\program files\Microsoft Visual......Any idea why? Since the executing assembly is not.?!
Nick
Is it because you're using the Web Development server that comes with VS ?
Timores
Yes.. I am. Can you suggest a good Silverlight\MVC tutorial or document? I believe what is happening is my application's starting page is Silverlight and when I attempt to move from this page the root context is differant. Meaning.. the uri is relative to my silverlight app and not the webserver.
Nick
A good Silverlight tutorial is the book "Silverlight 2 Unleashed", by L. Bugnion at Sams or Silverlight in Action at Mannings.I don't think I understand what you wrote about the starting page. Your app is a Web app, so the starting page is an HTML or ASPX page (from the Web project) that contains a reference to the Silverlight plug-in, which causes the XAP file created by the SL project to be loaded.Each part of the app (SL on the client, ASP.NET on the server) has its own "context".
Timores
A: 

The problem was that I was attempting to access this static resource as you would in typical ASP.net. However I found it necessary to map the path to the file using the current HTTPContext:

HttpContext.Current.Server.MapPath("~/App_Data/videos.xml");

So the above worked for me. Since this code is in the web project and not in the silverlight project I am still unclear as to why I cannot just access this resource using a relative path. This code will be executed in the context of the web server. i.e.

XDocument.load(../App_Data/videos.xml);
Nick