The Silverlight image control only supports loading pictures from any folder and Web page (http:\\**) of the project, which is a simpler way. So how to read the picture from FTP and display it. (I just transferred from ExtJS to Silverlight so the idea has been stuck in the image control should be able to load directly)
The main way is to use the Web service method through the FtpWebRequest request to the file and then in a byte transfer, of course you can also use the WCF service, can, after the service, on the server, add the following code:
[CSharp] View Plain copy print? [WebMethod (description = "get specified file stream", enablesession = true)] public byte[] getfile () { //fileinfo fileinfo=new fileinfo (file) string uri = FTP ://192.168.0.224/eca/001/0/356/png8-ask.jpg "; FtpWebRequest reqFtp; reqFtp = (FtpWebRequest) ftpwebrequest.create (New uri (Uri)); reqftp.credentials = new networkcrEdential ("ECA", "MIS5"); reqFtp.Method = WebRequestMethods.Ftp.DownloadFile; reqFtp.UseBinary = true; FtpWebResponse response = (FtpWebResponse) Reqftp.getresponse (); stream ftpstream = response. GetResponseStream (); memorystream mstream = new memorystream (); ftpstream.copyto (mstream); mStream.Position = 0; int length = (int) mstream.length; byte[] returnbyte = new byte[length]; mstream.read (returnbyte, 0, length); Mstream.close (); ftpstream.close ( ); response. Close (); return returnbyte; }
[WebMethod (Description = "Get specified file stream", EnableSession = True)] public byte[] GetFile () {
FileInfo fileinfo=new FileInfo (file) string uri = "Ftp://192.168.0.224/eca/001/0/356/png8-ask.jpg";
FtpWebRequest reqftp;
Reqftp = (ftpwebrequest) ftpwebrequest.create (new Uri (URI));
Reqftp.credentials = new NetworkCredential ("ECA", "MIS5");
Reqftp.method = WebRequestMethods.Ftp.DownloadFile;
Reqftp.usebinary = true;
FtpWebResponse response = (ftpwebresponse) reqftp.getresponse (); Stream FtpStream = Response.
GetResponseStream ();
MemoryStream mstream = new MemoryStream ();
Ftpstream.copyto (Mstream);
mstream.position = 0;
int length = (int) mstream.length;
byte[] Returnbyte = new Byte[length];
Mstream.read (returnbyte, 0, length);
Mstream.close ();
Ftpstream.close (); Response.
Close ();
return returnbyte; }
Then it is called from the front, the code is as follows:
[CSharp] View Plain copy print? Private void client_getfilecompleted (Object sender, getfilecompletedeventargs e) { byte[] buffer = e.Result; System.IO.MemoryStream stream = new System.IO.MemoryStream (buffer); system.windows.media.imaging.bitmapimage bmp = new System.Windows.Media.Imaging.BitmapImage (); bmp. SetSource (stream); Image Image1 = new image (); image1. source = bmp; tabitem tb = new tabitem ();            TB. header = "read system picture";            TB. content = image1;            TB. isselected = true; tal. Items.Add (TB); }
private void Client_getfilecompleted (object sender, Getfilecompletedeventargs e)
{
byte[] buffer = E.result;
System.IO.MemoryStream stream = new System.IO.MemoryStream (buffer);
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage ();
Bmp. SetSource (stream);
Image image1 = new Image ();
Image1. Source = BMP;
TabItem TB = new TabItem ();
Tb. Header = "read system picture";
Tb. Content = Image1;
Tb. IsSelected = true;
Tal. Items.Add (TB);
}
Where Tal is a table control, it runs the following results: