2

I have looked every where for my answer but couldn't find the right solution.Tried many solutions provided but still can't get it through.I uploaded an image in ftp server and i want it to get displayed into picture box in windows form without downloading it into local machine. Is it possible? Please include complete code for the solution......

Sharad Kumar
  • 61
  • 1
  • 10

2 Answers2

2

Here is a complete code: If any body needs.Make sure the image isn't large!!

public byte [] GetImgByte (string ftpFilePath)
{
    WebClient ftpClient = new WebClient();
    ftpClient.Credentials = new NetworkCredential(ftpUsername,ftpPassword);

    byte[] imageByte = ftpClient.DownloadData(ftpFilePath);
    return imageByte;
}

public static Bitmap ByteToImage(byte[] blob)
{
    MemoryStream mStream = new MemoryStream();
    byte[] pData = blob;
    mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
    Bitmap bm = new Bitmap(mStream, false);
    mStream.Dispose();
    return bm;
}
Community
  • 1
  • 1
Sharad Kumar
  • 61
  • 1
  • 10
0

You can use DownloadData to get a byte array and load that into the picturebox - see Download file directly to memory and How to put image in a picture box from a byte[] in C#

Community
  • 1
  • 1
NDJ
  • 5,189
  • 1
  • 18
  • 27
  • Using direct file path to the server gives error......... file not accessible... it might be because no credentials were supplied...... so how would i supply authenticate to the server before downloading data – Sharad Kumar Jun 29 '16 at 09:05
  • client.Credentials = new System.Net.NetworkCredential("username", "password"); – NDJ Jun 29 '16 at 09:17
  • Sorry to say but its not helping me out...... will it be possible if u could post a complete code regarding this specific problem...... – Sharad Kumar Jun 29 '16 at 10:08
  • the path u showed me is apparently doing something..... the code is working i guess... but the problem is the image that is being displayed is just a blue image nothing else.... still unable to figure it out please help!! @NDJ – Sharad Kumar Jun 30 '16 at 05:57
  • Glad you figured it out. Sorry couldnt answer comments, was asleep :) feel free to accept answer if it helped you to get to solution. – NDJ Jun 30 '16 at 06:17