Code Behind Page Page /Controls/FaceBookEntry.ascx.cs (C#)
Used by Page /Controls/FaceBookEntry.ascx (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Configuration;  
4: using Facebook;  
5: using FacebookSampleASPNETApp;  
6: using QuizNetOnline.Logic;  
7:   
8: public partial class FaceBookEntry : System.Web.UI.UserControl  
9: {  
10:     private string facebookName;  
11:   
12:     public string FacebookAppID  
13:     {  
14:         get  
15:         {  
16:             return ConfigurationManager.AppSettings["AppID"];  
17:         }  
18:     }  
19:   
20:     public string LabelMessage  
21:     {  
22:         get { return lblMessage.Text; }  
23:         set { lblMessage.Text = value; }  
24:     }  
25:   
26:     protected void Page_Load(object sender, EventArgs e)  
27:     {  
28:         FacebookConnect fbConnect = new FacebookConnect();  
29:   
30:         panelLoginButton.Visible = !fbConnect.IsConnected;  
31:         cmdFaceBook.Enabled = fbConnect.IsConnected;  
32:           
33:         if (fbConnect.IsConnected)  
34:         {  
35:             cmdFaceBook.ImageUrl = "~/images/SaveFaceBookNormal.jpg";  
36:   
37:             Facebook.FacebookAPI api = new Facebook.FacebookAPI(fbConnect.AccessToken);  
38:             try  
39:             {  
40:                 JSONObject me = api.Get("/" + fbConnect.UserID);  
41:                 facebookName = me.Dictionary["name"].String;  
42:                 lblName.Text = "Name: " + facebookName;  
43:   
44:             }  
45:             catch (Exception)  
46:             {  
47:                 panelLoginButton.Visible = true;  
48:             }  
49:               
50:         }  
51:         else  
52:         {  
53:             cmdFaceBook.ImageUrl = "~/images/SaveFaceBookDisabled.jpg";  
54:         }  
55:     }  
56:   
57:     protected void cmdFaceBook_Click(object sender, EventArgs e)  
58:     {  
59:         FacebookConnect fbConnect = new FacebookConnect();  
60:         if (fbConnect.IsConnected)  
61:         {  
62:             Facebook.FacebookAPI api = new Facebook.FacebookAPI(fbConnect.AccessToken);  
63:             JSONObject me = api.Get("/" + fbConnect.UserID);  
64:   
65:             Dictionary<string, string> postArgs = new Dictionary<string, string>();  
66:             postArgs["message"] = lblMessage.Text.Trim();  
67:   
68:             if (ConfigurationManager.AppSettings["BlockFBposting"] == null ||  
69:                 Convert.ToBoolean(ConfigurationManager.AppSettings["BlockFBposting"]) == false)  
70:             {  
71:                 api.Post("/" + fbConnect.UserID + "/feed", postArgs);  
72:             }  
73:   
74:             lblMesageResult.Text = "Posted a message to " + facebookName + "'s feed";  
75:   
76:             cmdFaceBook.Enabled = false;  
77:             cmdFaceBook.ImageUrl = "~/images/SaveFaceBookDisabled.jpg";  
78:   
79:             Log log=new Log();  
80:             log.Save(((UserWeb)Session["userWeb"]).UserName + " has posted a message to Facebook");  
81:         }  
82:         else  
83:         {  
84:             lblMesageResult.Text = "No message sent, unauthenticated facebook user";  
85:         }  
86:   
87:           
88:     }  
89: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.