Post Photo and Status On Facebook using C#

First of all add FaceBookAPI.dll in your project.

Then after add name space : using FaceBookAPI;

Default1.aspx.CS

  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.    FaceBookConnect.Authorize("publish_actions","http://localhost:123/Default2.aspx");   
  4. }   
Default2.aspx
  1. <html lang="en">  
  2.   
  3. <head id="Head1" runat="server"> </head>  
  4.   
  5. <body>  
  6.     <form id="form1" runat="server">  
  7.         <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine"></asp:TextBox>  
  8.         <asp:FileUpload ID="FileUpload1" runat="server"></asp:FileUpload>  
  9.         <hr />  
  10.         <asp:Button ID="btnUpload" runat="server" Text="Ulpoad" OnClick="btnUpload_Click" /> </form>  
  11. </body>  
  12.   
  13. </html>  
When we click on upload button then it post photo and text on your Facebook account.

Default2.aspx.CS
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.     FaceBookConnect.API_Key = "App Key";  
  4.     FaceBookConnect.API_Secret = "App Secret Key";  
  5.     if (!IsPostBack)  
  6.     {  
  7.         string code = Request.QueryString["code"];  
  8.         if (!string.IsNullOrEmpty(code))  
  9.         {  
  10.             ViewState["Code"] = code;  
  11.         }  
  12.     }  
  13. }  
  14. protected void btnUpload_Click(object sender, EventArgs e)  
  15. {  
  16.     Dictionary < stringstring > data = new Dictionary < stringstring > ();  
  17.     data.Add("caption""nikhil sangani");  
  18.     data.Add("name""nikhil sangani");  
  19.     data.Add("message", txtMessage.Text);  
  20.     Session["File"] = FileUpload1.PostedFile;  
  21.     Session["Message"] = txtMessage.Text;  
  22.     FaceBookConnect.Post(ViewState["Code"].ToString(), "me/feed", data);  
  23.     FaceBookConnect.PostFile(ViewState["Code"].ToString(), "me/photos", (HttpPostedFile) Session["File"], Session["Message"].ToString());  
  24. }