locked
Silverlight - To contain a js/html5 webpage RRS feed

  • Question

  • Is Silverlight the right thing for this?

    I have written a webpage entirely in html5/js. I want to port is soley to a desktop application, however, I do not want to rewrite all the code in c# or c++.

    Could I somehow use Silverlight as a container for my webpage, which I could package all together in the Silverlight OOB thing, so I could get a launch icon on the desktop/start menu.

    I am not sure I am explaining this well. Basically I want to create a new Silverlight OOB project in Visual Studio. Put my webpage and js files into it somehow (with minimal recoding), then compile the thing into a xap file for the desktop.

     

    Wednesday, May 16, 2012 6:50 AM

Answers

  • Hi ,

      I did a sample just now.  I tried to include a html file in my project. Its name is Hello.html , and its Build action was set to Embedded Resource.  I used a WebBrowser control to get that file content and render it. It was working fine. 

                Assembly thisAssembly = Assembly.GetExecutingAssembly();  
                string[] resNames = thisAssembly.GetManifestResourceNames(); 
                foreach (string resName in resNames)
                {
                    if (resName.ToLower().EndsWith("hello.html"))  
                    {
                        // To get only the file name that ends with .html
                        int j = resName.IndexOf('.');
                        string myres = resName.Substring(j+1);
                        
                        
                        // To get the folder where that file is present.
                        string str = Application.Current.Host.Source.LocalPath.ToString();
                        int i = str.LastIndexOf('\\');
                        str = str.Substring(0, i+1);
                        str += myres;
    
                        //Open the html in the browser
                        FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read);
                        StreamReader sr = new StreamReader(fs);
                        string s = sr.ReadToEnd();
                        sr.Close();
                        fs.Close();
                        webBrowser1.NavigateToString(s);
                        break;
                    }
                } 

      Implies that you can put your html5 page in your project, and access it like a desktop app .

    Hope it Helps Laughing

    Wednesday, May 16, 2012 9:45 AM

All replies

  • Hi ,

       I think you can make this work. All you are trying to do is display a html page inside a silverlight OOB application.  (Which can be done in an overlay or Web browser control)

      Please check out this : http://weblogs.asp.net/dwahlin/archive/2010/05/10/integrating-html-into-silverlight-applications.aspx

     Hope it Helps Laughing

    Wednesday, May 16, 2012 8:09 AM
  • Thanks for the reply. I am reading that now.

    However, one thing I probably did not make clear in my original post. I dont want the html5/js webpage on the web, I want it on the user's desktop, as an integral part of the xap file. (I am trying to get my html5/js webpage off the web to a desktop/silverlight/oob with literally no recoding of the html5/js. All the coding I want to do is the silverlight/oob coding. Basically, once the silverlight oob program is installed, the user then does not need to have any active web connection.)

    Wednesday, May 16, 2012 9:00 AM
  • Hi ,

      I did a sample just now.  I tried to include a html file in my project. Its name is Hello.html , and its Build action was set to Embedded Resource.  I used a WebBrowser control to get that file content and render it. It was working fine. 

                Assembly thisAssembly = Assembly.GetExecutingAssembly();  
                string[] resNames = thisAssembly.GetManifestResourceNames(); 
                foreach (string resName in resNames)
                {
                    if (resName.ToLower().EndsWith("hello.html"))  
                    {
                        // To get only the file name that ends with .html
                        int j = resName.IndexOf('.');
                        string myres = resName.Substring(j+1);
                        
                        
                        // To get the folder where that file is present.
                        string str = Application.Current.Host.Source.LocalPath.ToString();
                        int i = str.LastIndexOf('\\');
                        str = str.Substring(0, i+1);
                        str += myres;
    
                        //Open the html in the browser
                        FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read);
                        StreamReader sr = new StreamReader(fs);
                        string s = sr.ReadToEnd();
                        sr.Close();
                        fs.Close();
                        webBrowser1.NavigateToString(s);
                        break;
                    }
                } 

      Implies that you can put your html5 page in your project, and access it like a desktop app .

    Hope it Helps Laughing

    Wednesday, May 16, 2012 9:45 AM