Saturday, February 04, 2012
Blog
Mar 6

Written by: New Age Solution
3/6/2010 6:06 PM  RssIcon

downloads/PassingLargeText.zipWe will look at passing large text to Silverlight using InitParams and then we will take a look at using Fiddler to see what gets passed into Silverlight.

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">

        <param name="source" value="ClientBin/PassingLargeText.xap"/>

        <param name="onError" value="onSilverlightError" />

        <param name="background" value="white" />

        <param name="minRuntimeVersion" value="4.0.41108.0" />

        <param name="autoUpgrade" value="true" />

        <param name="initparams" id="XamlInitparams" runat="server" />

        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.41108.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>div>

Download Source

 

In Web Application Project

1) In ASPX page create param named initparams and to be able to access code behind give it an id and set runat equals server.

2) In page load of code behind read the image file and IMPORTANT thing to note is to convert to base 64 string. Converting to base 64 string is important specially dealing with binary files and it would be the safest way to deal with any type of file. I had case where when object was serialized and it would fail to pass via initparams because of starge chars when object was serialized.

protected void Page_Load(object sender, EventArgs e)

    {

      string data = Convert.ToBase64String(File.ReadAllBytes(Server.MapPath("newagesolution_logo.png")));

      XamlInitparams.Attributes["value"] = "MyTestFile=" + data;

    }

 

 

In Silverlight Application

 

1) In the startup of App.xaml get InitParam which is key / value of dictionary and pass it to MainPage

 

private void Application_Startup(object sender, StartupEventArgs e)

    {

      string mytestFile = e.InitParams["MyTestFile"];

      this.RootVisual = new MainPage(mytestFile);

    }

 

 2) In MainPage.xaml

 

public MainPage(string myTestFile)

    {

      InitializeComponent();

      MemoryStream ms = new MemoryStream(Convert.FromBase64String(myTestFile));

      BitmapImage src = new BitmapImage();

      src.SetSource(ms);

      Image img = new Image();

      img.Source = src;

      this.LayoutRoot.Children.Add(img);

    }

 

In Fiddler

 

1) Use 127.0.0.1.  ; Dot at the end of ip is not a typo. In order to use fiddler in localhost development you have to put the dot at the end of the ip.

 

 

2) In hexview you can see that it is passing initparms.

 

 

Conclusion

 

In this example I read image file BUT there are much better way to read image file. Image file was used to demonstrate the read of binary file and passing successfully into Silverlight. In real world, you might end up serializing DataContract and passing it to Silverlight. Why?

 

1) because sometimes you might not have access to the WCF service

2) in production say certain request was crashing the app and luckily say WCF traffic was logged. You can simply serialize and send the object into Silverlight for troubleshooting.

 

I tested as big as 5 MB file and then when things got bigger I simply zipped and unzipped in Silverlight so I never had need to go beyaond 5 MB file.

 


Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 


Tags


Blog Archive


Blog List


Search Blog


Google Reader


Blog Comments
re:
I’m impressed. Very informative and trustworthy blog does exactly what it sets out to do. I’ll bookmark your weblog for future use.

Joseph
www.joeydavila.com
Your online Library
Re: Silverlight 4 PathListBox
Nope you dont need blend.
Re: Silverlight 4 PathListBox
I have visual studio 2010, do you have to have expression blend to execute the above code? Thanks.
re:
I’m impressed. Very informative and trustworthy blog does exactly what it sets out to do. I’ll bookmark your weblog for future use.

Joseph
www.joeydavila.com
Your online Library
re:
I’m impressed. Very informative and trustworthy blog does exactly what it sets out to do. I’ll bookmark your weblog for future use.

Joseph
www.joeydavila.com
Your online Library
Re: How to fix TF215032 when trying to delete Build Definition from TFS?
Thanks you very much.
Re: DotNetNuke PermanentRedirect Error
Thanks so much for posting this! It fixed my issue.
Re: Why we are using our own custom blog using DotNetNuke?
Word Press is good too. see Blog.ToeTapz.com. Depends on what you need. I use DNN blog because it gives me ultimate control on what I want and what I need. Also I need to be able to upload Silverlight demo so I use DNN. BlogToeTapz.com I recently got is using word press and I been happy with it so far.
I am testing DNN blogs and they are not as good as blogger.com
Are there any other DNN blogs we can use for this?

http://newmediaworlds.blogspot.com/





Re: How to add Google Email, Calendar, and contacts to Blackberry and iPhone?
Great and detail instructions. I got just got my Blackberry 8350 and it's a very useful information for me as a newbie.


Syndicate  

Privacy Statement  |  Terms Of Use
Copyright 2010 New Age Solution