0

I have a question related to accessing an online Silverlight XAP file from a HTML page that is stored locally on my C:/ drive. I will need the Silverlight application to access a large file that I would prefer to store on the client machine in order to speed up the whole process. What I would like to do is to write the HTML file on the client’s hard drive with the required content embedded in it which in turn will trigger the Silverlight app who will be able to access the data in the DOM.

This works in Visual Studio but when I create the HTML page locally and open it, then the Silverlight app is not being run. Either the app does not run and the page is empty or I am notified that Silverlight needs to be installed even though it already is.

I am aware that running a Silverlight app as a trusted application will allow access to the hard drive but I am exploring options that will not require any user input in the process.

I have tried adding the Silverlight section dynamically to the web page using JavaScript but this has not worked. I get the same problems. The JavaScript code is below and I’ve tested it from an online location and the Silverlight is being launched there.

    function applyChanges(){ 
  var theDiv = document.getElementById("silverlightControlHost");
  theDiv.innerHTML = '<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"><param name="source" value="http://online.company.net/ClientBin/company_xap.xap"/><param name="onError" value="onSilverlightError" /><param name="background" value="white" /><param name="minRuntimeVersion" value="4.0.60310.0" /><param name="autoUpgrade" value="true" /><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration:none"><img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/></a></object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>';
}

I have been able to connect to the app using an iframe embedded in the local HTML file but this limits the access I require for the DOM in order to pull the required content.

I have also tried loading HTML content into a WebBrowser control from memory in a Windows Forms Application but while the rest of the HTML is displayed, the Silverlight app is still missing.

Is there any way to access an online Silverlight application from a local HTML file?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tom
  • 365
  • 3
  • 19

1 Answers1

0

Well, I'm not sure why it's not loading from a local html but here are some workarounds that could help you

  • Host your html in your client iis if this is applicable that seems to work just fine.

Or if this is not possible try this

  • First create a html page that will load your xap file on the server where you host the xap file

and in the local html file just load the html page inside an iframe like this

   <iframe **id="xapHost"** src="http://astrocoder.com/BlogFiles/Silverlight/test.html?id=5" 
    frameborder="0" 
    style="width:500px;height:500px">

To load the xap file with custom parameters you could add query string parameters to your iframe src url like the url above and in your JavaScript you could retrieve these values and build your object with the new parameter.

To read query string values in JavaScript check this question and to change the iframe src dynamically you could do it like that

document.getElementById('xapHost').src = "http://astrocoder.com/BlogFiles/Silverlight/test.html?id=6&anyparam=anything";

I hope this could help

Community
  • 1
  • 1
Mahmoud Ibrahim
  • 1,703
  • 15
  • 15
  • Hi Mahmoud, Thanks for the reply. I don't think option 1 would be possible. There is no guarantee that IIS would be available in all instances. – Tom Jun 10 '13 at 15:11
  • Hi Mahmoud, Thanks for the reply. I don't think option 1 would be possible. There is no guarantee that IIS would be available in all instances. I have been experimented with the iframe option in the past and it is the closest solution that I have come across. I still need to write the parameters into the DOM in the parent HTML page. The parameters are being written into hidden fields on the parent page. At the moment I cannot access these parameters using the Silverlight app contained in the iframe. Do you know of a way to get the parameters into the app through the iframe? – Tom Jun 10 '13 at 15:25
  • I've edited the answer above to pass custom parameters through the iframe – Mahmoud Ibrahim Jun 10 '13 at 22:17
  • Adding query string values is something I have investigated and it is something that can work in this case. Unfortunately, one of the parameters is supposed to be a file that will be between 4MB and 5MB. This doesn't work when I try to add it as a parameter in this fashion. – Tom Jun 11 '13 at 09:06
  • Can't you pass the url to the file and download the file from the url instead ?! – Mahmoud Ibrahim Jun 12 '13 at 10:09