Post Image in Facebook using C# and FacebookMediaStream

 For posting images on FB there are 2 ways:

  1. FacebookMediaObject
  2. FacebookMediaStream

Following are the code for FacebookMediaStream.

  1. var fb = new FacebookClient(pAccessToken);  
  2. string attachementPath = @"C:\\yogesh\\2.jpg";  
  3. using (var file = new FacebookMediaStream  
  4. {  
  5.    ContentType = "image/jpeg",  
  6.    FileName = Path.GetFileName(attachementPath)  
  7. }.SetValue(File.OpenRead(attachementPath)))  
  8. {  
  9.    dynamic result = fb.Post("me/photos",  
  10.    new { message = "upload using Facebook SDK for .NET", file });  
  11. }