简体   繁体   中英

access to a folder in asp.net web application through silverlight application

我们如何通过Silverlight应用程序访问.jpg文件,这些文件在asp.net Web应用程序的文件夹中?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM