AngularJS , Angular 2/4/5 , JavaScript , Jquery , MongoDB , ASP.NET MVC 4/5, Entity Framework 4.1/5/6 , WPF , Silverlight , SQL Server


Almost every application need to store image,content etc for some operations.We had a requirement 1) to store the images at server 2)store some template at client side so that operations will be carried out at client side.

Adding file as Resource in Silverlight Application:

In Silverlight one can store the image,files in the resources.Following are the steps to store the files in Resource:              

1.Add New File in the silverlight project.for instance say.. we have added file- “CWTemplateXML.xml” in our silverlight application.

2.Set the property -“Build Action” to “Embeded Resource”.Please refere below image for more clarification.

 

SilverlightResource

3. Now we can read the file stream using following code:

 ‘Reading from Resources

 Note : “SilverlightExcelReadUsingMSOfficeFormat” is the projec name.

 

Using Str As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream(“SilverlightExcelReadUsingMSOfficeFormat.CWTemplateXML.xml”)

”We have read the strean in “str” variable.now you can use it for your purpose.

”I am creating the XDocument from this stream in below code.

Dim xmlRd As XmlReader = XmlReader.Create(Str)Dim xmlDoc As XDocument

 End Using

 Now, We will see how to add files in XAP file and how to read it.Following is the step wise description for it :

1.Add file in the Silverlight project. for instance say we are adding -“Leadsheet.xlsx”

2.Set the property -“Build Action” to “Content”.Please refere below image for more clarification.

Adding File in XAP

Adding File in XAP

3.Now to read file . we have to use class – “WebClient” and need to add “OpenReadCompleted” event handler as follows:

  Private Sub xapReadCompleted(ByVal send As Object, ByVal e As OpenReadCompletedEventArgs)

Dim streamXAP As New StreamResourceInfo(e.Result, Nothing

) 

 

 

Dim streamFile As StreamResourceInfo = Application.GetResourceStream(streamXAP, New Uri(“Leadsheet.xlsx”

, riKind.Relative))  

 

End Sub

 Private Sub Button_Click(ByVal sender As System.Object, ByVal e As S

ystem.Windows.RoutedEventArgs) 

 

 

 Dim wc As New

WebClient() 

 

 

AddHandler wc.OpenReadCompleted, AddressOf

xapReadCompletedwc.OpenReadAsync(

 

New Uri(“SilverlightExcelReadUsingMSOfficeFormat.xap”

, UriKind.RelativeOrAbsolute)) 

 

 End Sub

 Note : “SilverlightExcelReadUsingMSOfficeFormat” is the projec name.

 Please refer following links for more information:

http://pietschsoft.com/post/2008/03/Silverlight-Anatomy-of-an-XAP-file.aspx
http://www.sharpgis.net/post/2009/04/21/REALLY-small-unzip-utility-for-Silverlight.aspx

Comments on: "Reading Content from XAP and Resource in Silverlight" (1)

  1. Quite a beautiful website. I built mine and i was looking for some ideas and you gave me a few. Did you develop the website alone?

    Thank you

Leave a comment