C# .NET - How to save Profile image of facebook using c#

Asked By pankaj singh on 19-Feb-13 05:39 AM
Danasegarane Arunachalam replied to pankaj singh on 19-Feb-13 06:43 AM
From Google

public static string GetPictureUrl(string faceBookId)
    {
        WebResponse response = null;
        string pictureUrl = string.Empty;
        try
        {
            WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/picture", faceBookId));
            response = request.GetResponse();
            pictureUrl = response.ResponseUri.ToString();
        }
        catch (Exception ex)
        {
            //? handle
        }
        finally
        {
            if (response != null) response.Close();
        }
        return pictureUrl;
    }
pankaj singh replied to Danasegarane Arunachalam on 20-Feb-13 03:18 AM
It's Good but it only return the url,

but how to slove on local disk.
Danasegarane Arunachalam replied to pankaj singh on 20-Feb-13 03:24 AM
After returning the URL call the Save method of webclient class as


 static void Main(string[] args)
      {
       
        string pictureurl = GetPictureUrl("facebookid");
        //Save the file

        WebClient webClient = new WebClient();
        webClient.DownloadFile("pictureurl", @"c:\myfile.jpg");

      }


      public static string GetPictureUrl(string faceBookId)
      {
        WebResponse response = null;
        string pictureUrl = string.Empty;
        try
        {
          WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/picture", faceBookId));
          response = request.GetResponse();
          pictureUrl = response.ResponseUri.ToString();
        }
        catch (Exception ex)
        {
          //? handle
        }
        finally
        {
          if (response != null) response.Close();
        }
        return pictureUrl;
      }