access to a folder in asp.net web application through silverlight application
How can we access through my silverlight application to .jpg files that these fi开发者_JAVA百科les within a folder in asp.net web application?
As you know Silverlight applications run on the client machine, inside the SL browser plugin; this all alone implies and forces the fact that a server resource like a file is not available in there and cannot be accessed by path (either absolute or relative...).
What you should probably do is expose some services (like WCF end points) which allow you to retrieve the file content from the server side then render it in the SL application.
There are plenty of examples online, I found this article with some sample code as well ready to download.
Loading Files From a Remote Server in Silverlight
Edit: if you have the full url of the image you can also use other approaches because the image will be available at that url served by the web server already and will not need any additional effort to be transmitted, for example:
<Canvas x:Name="LayoutRoot" Background="White">
<Image x:Name="MyImage"></Image>
</Canvas>
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
BitmapImage bi = new BitmapImage();
bi.UriSource = new Uri("http://www.silverlightdev.net/images/blogImages/Sample.png");
MyImage.Source = bi;
MyImage.ImageOpened += new EventHandler<RoutedEventArgs>(MyImage_ImageOpened);
}
void MyImage_ImageOpened(object sender, RoutedEventArgs e)
{
// Image load complete.
}
}
I have copied this code directly from here:
Silverlight Tip of the Day #86 – How to Load External Images
精彩评论