This is a mirror of official site: http://jasper-net.blogspot.com/

Silverlight: Reading from a File Contained in your XAP

| Thursday, December 30, 2010
The approach you take to reading from a file that is contained in your XAP is different from one you might take reading a file that is on a server or one that you have copied over to your ClientBin (which could be done using WebClient).

To do this first add the file to your Silverlight project and set the Build Action for this file to be of type Resource.

Next, create a URI that points to the file like I do below and create a StreamResourceInfo from the URI.

Uri uri = new Uri("SilverlightApplication6;component/MyFile.txt", UriKind.Relative)
StreamResourceInfo streamInfo = Application.GetResourceStream(uri);

Replace SilverlightApplication6 above with the namespace used in your Silverlight application. Replace MyFile.txt with the name of your file you added to your Silverlight project.

Next, get the Stream object from StreamResourceInfo and you can then create a StreamReader from the Stream.

if (null != streamInfo)
{
   Stream stream = streamInfo.Stream;
   StreamReader sr = new StreamReader(stream);

Read more: Everything Silverlight

Posted via email from .NET Info

0 comments: