Reader Level:

Post on Facebook Users Wall Using ASP.Net C#

By Raj Kumar Beniwal on Feb 27, 2013
This article demonstrates how to post content (status, image, video, URL) to a user's Facebook wall using ASP.Net.

This article demonstrates how to post content (status, image, video, URL) to a user's Facebook wall using ASP.Net. Since I was thinking of implementing this feature in my current project, I found something cool and decided to share it with C# Corner readers.

Getting Started

First of all create a new website in ASP.Net using C#. And now login into Facebook and click on the developer link and create a new app and supply an app name and click "Continue".



Now supply the captcha code in the TextBox and click "Continue".


Image 2.

As you can see, there is an AppID and App Secret. You must use these so copy them. And supply the site URL and click "Save changes".


Image 3.

Now let's start working on the UI. In this sample I will explain two ways to post a feed.

First scenario

  <script src="//" type="text/javascript"></script>

    <div id="fb-root">



        window.fbAsyncInit = function () {

            FB.init({ appId: '491677990891136', status: true, cookie: true,

                xfbml: true



        (function () {

            var e = document.createElement('script'); e.async = true;

            e.src = document.location.protocol +



        } ());


    <script type="text/javascript">

        $(document).ready(function () {

            $('#share_button').click(function (e) {




    method: 'feed',

    name: 'jQuery Dialog',

    link: '',

    picture: '',

    caption: 'This article demonstrates how to use the jQuery dialog feature in ASP.Net.',

    description: 'First of all make a new website in ASP.Net and add a new stylesheet and add .js files and put images in the images folder and make a reference to the page.',

    message: 'hello raj message'








        <input type="button" id="share_button" value="Share" />


Run application


Image 4.

Type a message and click "Share".


Image 5.

Login to Facebook and see wall posts.

Second scenario

Add the Facebook client assembly in the bin folder and work on the code behind.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Net;

using System.IO;

using Facebook;


public partial class Default2 : System.Web.UI.Page


    string bodymessage = "This is test message description new";

    protected void Page_Load(object sender, EventArgs e)





    private void CheckAuthorization()


            string app_id = "APP_ID";

            string app_secret = "APP_SECRET";

            string scope = "publish_stream,manage_pages";


            if (Request["code"] == null)




                    app_id, Request.Url.AbsoluteUri, scope));




                Dictionary<string, string> tokens = new Dictionary<string, string>();


                string url = string.Format("{0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",

                    app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);


                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;


                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)


                    StreamReader reader = new StreamReader(response.GetResponseStream());


                    string vals = reader.ReadToEnd();


                    foreach (string token in vals.Split('&'))


                        tokens.Add(token.Substring(0, token.IndexOf("=")),

                            token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));




                string access_token = tokens["access_token"];


                var client = new FacebookClient(access_token);


                client.Post("/me/feed", new { message = bodymessage });




Run the application to see the result.


Image 6.


Raj Kumar Beniwal
Raj Kumar Beniwal

Raj Kumar Beniwal is two time Microsoft MVP(Client App Dev) and four time C# Corner MVP,  working as project manager with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Serv... Read more



Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.

Trending up