locked
Access resources located in XAP RRS feed

  • Question

  • Hi there

    My server-side code must access the localization resources residing in Silverlight project (hosting on the same Web-server, same project). How to approach this task? It must be 2-step process:

    1. Find XAP in a folder and decompress it in memory

    2. Extract a .res file and load it into a Web-project memory for using

    Is that right? Any clue how to accomplish each step?

    Thanks.

    Wednesday, June 3, 2015 2:37 PM

Answers

  • Hi Renziglov,
    >>1. Find XAP in a folder and decompress it in memory
    Please find XAP in server-side with System.AppDomain.CurrentDomain.BaseDirectory + "ClientBin\\***.xap". System.AppDomain.CurrentDomain.BaseDirectory helps us find the absolute path of current application. Then please decompress XAP with DotNetZip Library from http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples

    >>2. Extract a .res file and load it into a Web-project memory for using
    DotNetZip Library will help us get all file in XAP. Please decompress files into MemoryStream and read the file with StreamReader. Following code have been tested and worked fine in my side, please try it. If any question, feel free to let me know.

    	    using Ionic.Zip;
    
                //Get the path of the XAP file
                string zipToUnpack = System.AppDomain.CurrentDomain.BaseDirectory + "ClientBin\\***.xap";
    
                //Unzip the XAP file with ZipFile
                using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
                {
                    // extract the file in XAP
                    foreach (ZipEntry e in zip1)
                    {
                        using (var ms = new MemoryStream())
                        {
                            e.Extract(ms);
    
                            // The StreamReader will read from the current position of the MemoryStream which is currently 
                            // We need to set the position to 0 in order to read from the beginning.
                            ms.Position = 0;
                            var sr = new StreamReader(ms);
                            var myStr = sr.ReadToEnd();
       
                        }
                    }
                }

    Best Regards,
    Weiwei



    • Edited by Weiwei Cai Thursday, June 4, 2015 6:40 AM
    • Marked as answer by Renziglov Thursday, June 4, 2015 2:55 PM
    Thursday, June 4, 2015 6:39 AM
  • These are the same project????

    Why would you not just share the res file source between the web and Silverlight projects?

    Add > existing file > go find the res file, choose as link in the combo bottom right.

    You would just have it directly there in your web project to use then.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles


    • Edited by Andy ONeill Thursday, June 4, 2015 8:13 AM
    • Marked as answer by Renziglov Thursday, June 4, 2015 2:55 PM
    Thursday, June 4, 2015 8:11 AM

All replies

  • Hi Renziglov,
    >>1. Find XAP in a folder and decompress it in memory
    Please find XAP in server-side with System.AppDomain.CurrentDomain.BaseDirectory + "ClientBin\\***.xap". System.AppDomain.CurrentDomain.BaseDirectory helps us find the absolute path of current application. Then please decompress XAP with DotNetZip Library from http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples

    >>2. Extract a .res file and load it into a Web-project memory for using
    DotNetZip Library will help us get all file in XAP. Please decompress files into MemoryStream and read the file with StreamReader. Following code have been tested and worked fine in my side, please try it. If any question, feel free to let me know.

    	    using Ionic.Zip;
    
                //Get the path of the XAP file
                string zipToUnpack = System.AppDomain.CurrentDomain.BaseDirectory + "ClientBin\\***.xap";
    
                //Unzip the XAP file with ZipFile
                using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
                {
                    // extract the file in XAP
                    foreach (ZipEntry e in zip1)
                    {
                        using (var ms = new MemoryStream())
                        {
                            e.Extract(ms);
    
                            // The StreamReader will read from the current position of the MemoryStream which is currently 
                            // We need to set the position to 0 in order to read from the beginning.
                            ms.Position = 0;
                            var sr = new StreamReader(ms);
                            var myStr = sr.ReadToEnd();
       
                        }
                    }
                }

    Best Regards,
    Weiwei



    • Edited by Weiwei Cai Thursday, June 4, 2015 6:40 AM
    • Marked as answer by Renziglov Thursday, June 4, 2015 2:55 PM
    Thursday, June 4, 2015 6:39 AM
  • These are the same project????

    Why would you not just share the res file source between the web and Silverlight projects?

    Add > existing file > go find the res file, choose as link in the combo bottom right.

    You would just have it directly there in your web project to use then.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles


    • Edited by Andy ONeill Thursday, June 4, 2015 8:13 AM
    • Marked as answer by Renziglov Thursday, June 4, 2015 2:55 PM
    Thursday, June 4, 2015 8:11 AM
  • Yes, this is the simpliest way, indeed.

    Thanks.

    Thursday, June 4, 2015 2:56 PM