Post files in FaceBook wall using Graph API

Steps to Post files in FaceBook wall using Graph API is given below.

1)Create a Facebook application to get an AppID and Secret key for your Website or Blog. Use the following link to open Facebook developers App site.


2)Add App ID,secret key in code and also make reference to DLL for Facebook integration.

Download DLL for FaceBook Integration here

Aspx Code

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <h2>Upload or post photos, images, or pictures to FaceBook wall with comments using Graph API in ASP.Net website</h2>
            <asp:FileUpload ID="FileUpload_Demo" runat="server" />
            <br />
            <br />
            <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine"></asp:TextBox>
            <hr />
            <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadPhoto" />


C# Code

protected void Page_Load(object sender, EventArgs e)
           string API_Key = ConfigurationManager.AppSettings["API_Key"];
           string API_Secret = ConfigurationManager.AppSettings["API_Secret"];
           FaceBookConnect.API_Key = API_Key;
           FaceBookConnect.API_Secret = API_Secret;
           if (!IsPostBack)
               string code = Request.QueryString["code"];
               if (!string.IsNullOrEmpty(code))
                   FaceBookConnect.PostFile(code, "me/photos", (HttpPostedFile)Session["File"], Session["Message"].ToString());
                   Session["File"] = null;
                   Session["Message"] = null;

       protected void UploadPhoto(object sender, EventArgs e)
           Session["File"] = FileUpload_Demo.PostedFile;
           Session["Message"] = txtMessage.Text;
           FaceBookConnect.Authorize("user_photos,publish_actions", Request.Url.AbsoluteUri.Split('?')[0]);



The below demo shows how the post/image gets posted in facebook on Upload button click.


Image posted in FaceBook Wall on Upload button click

Post files in FaceBook wall using Graph API





Demo Code