Wednesday, November 14, 2012

Creating a facebook app

This is a step by steb tutorial for creating a facebook app. At first you have to register as a facebook developer in  https://developers.facebook.com/ , Then download the dll's FBHelper.dll and NewtoSoft.dll from this link

step:1 Navigate to https://developers.facebook.com/ and click on the app link.

 

step:2 click on the create new app button


step:3 Enter the app name and name space. name space is simple a name which is used to identify   your app.


step 4: Complete the capche.

step:5  You will get a unique app id and app secret code. Sandboxmode should be enabled while creating and testing your app.


step 6: Open your visual studio and create an asp.net website. this is for getting your testing url.

step 7: add new page.
 

step 8: add the following dll's to your projects. Newtonsoft is not requered unless you are not using the direct FQL method from the FBHelper.

 
 step 9: Take the properties of your website by rightclicking on the site annd change the target framework to 4, because FBHelper.dll supports only from dotnet 4.0.

step 10: take your site url by running your website.


step 11: https://developers.facebook.com/ and change your canvase url. this url will be called after the user authenticate your app.

step 12:  Customize your permissions.

step 13: add
using FBHelper;
using FBHelper.Entity;  namespaces. then you are ready to go. see the below screen shots


Thursday, November 8, 2012

Facebook graph api

Sample application created using the following dll's

Get your blessing word https://christopher.azurewebsites.net/ 

You can create a facebook application simply using these dll's.
download these dll's from the following links.
FBHelper.dll
NewtonSoft JSON

then you need to create a facebook app using the link fbapp and then navigate to create facebook app page and do the processings and the get the appID and appsecret.

then


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using FBHelper;
using FBHelper.Entity;
using System.IO;


namespace FacebookApp
{
    public partial class AppPage : System.Web.UI.Page
    {
        FB fbApp = new FB();

        protected void Page_Load(object sender, EventArgs e)
        {
            string imageUrl = Server.MapPath(@"/image/Hydrangeas.jpg");

            fbApp.AppID = "YOUR_APP_ID";
            fbApp.AppSecret = "YOUR_APP_SECRET";
            fbApp.RedirectURL = "http://localhost:51337/AppPage.aspx";
            string code = Request.QueryString["code"] as string;
            string error = Request.QueryString["error_description"] as string;

            if (string.IsNullOrEmpty(error))
            {
                if (string.IsNullOrEmpty(code))
                {
                    Response.Redirect(fbApp.CodeRequestURL);
                }
                else
                {
                    fbApp.Code = code;
                    fbApp.GetAccessToken();
                    string token = fbApp.AccessToken;
                    FBUser user = fbApp.GetMe();
                    List<FBUser> friends = fbApp.GetMyFriends();
                    List<Photo> pics = fbApp.GetMyPhotos();

                    string statusID = fbApp.UpdateStatus(user.ID, "hiiiii");
                    string album = fbApp.CreateAlbum(user.ID, "Sample", "new sample");
                    List<Album> alb = fbApp.GetAllAlbumDetails();
                    List<Likes> like = fbApp.GetAllLikesByMe();

                    fbApp.UploadPhoto("Sample Image", imageUrl);
                    fbApp.UploadPhotoToAnAlbum(album, "Hiiiiii", imageUrl);
                }
            }
        }
    }
}




Facebook direct fql query using c#





string query= "select aid,name,cover_pid,created,modified,description from album where owner=me()";
string data = string.Empty;
Uri uri = new Uri("https://graph.facebook.com fql?q=" + query + "&access_token=" + accessToken);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = (Stream)response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();

Facebook get all album



first you should check the permisson on facebook https://developers.facebook.com/docs/reference/login/user-friend-permissions/

string data = string.Empty;
Uri uri = new Uri("https://graph.facebook.com/me/albums?access_token=" + token);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = (Stream)response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();

Facebook get all photos

first you should check the permisson on facebook https://developers.facebook.com/docs/reference/login/user-friend-permissions/



string data = string.Empty;
Uri uri = new Uri("https://graph.facebook.com/me/photos?access_token=" + token);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = (Stream)response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();

Facebook get all friends



frist you should check the permisson on facebook https://developers.facebook.com/docs/reference/login/user-friend-permissions/

string data = string.Empty;
Uri uri = new Uri("https://graph.facebook.com/ me/friends?access_token=" + token);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = (Stream)response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();

Facebook Get loggedin user details using c#



 
string data = string.Empty;
Uri uri = new Uri("https://graph.facebook.com/me?access_token=" + token);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = (Stream)response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();

Facebook Upload Photo using c#

You can either create one album and upload to the album, otherwise you can upload to the default album of your app.
In order to publish a photo to a user’s album, you must have the publish_stream permission. With that granted, you can upload a photo by issuing an HTTP POST request with the photo content and an optional description to one these to Graph API connections:
  • https://graph.facebook.com/USER_ID/photos - The photo will be published to an album created for your app. We automatically create an album for your app if it does not already exist. All photos uploaded this way will then be added to this same album.
  • https://graph.facebook.com/ALBUM_ID/photos - The photo will be published to a specific, existing photo album, represented by the ALBUM_ID. 
 Upload to the default album



WebClient client = new WebClient();
client.UploadFile("https://graph.facebook.com/me/photos?access_token=" + accessToken + "&message=" + name, "POST", path);  


upload to the particular album


WebClient client = new WebClient();
client.UploadFile("https://graph.facebook.com/" + albumID + "/photos?access_token=" + accessToken + "&message=" + name, "POST", path);
 

  

Tuesday, September 25, 2012

Disable Right Click In a Web Page

We can disable right click on apage using the following code

  <script type="text/javascript">
        document.onmousedown = clickfn;

        function clickfn(e) {
            var button;
            if (navigator.appName == "Microsoft Internet Explorer") {
                button = event.button;
              
            }
            else {
                button = e.buttons;
            }

            if (button == 2) {
                alert("Right Click Disabled");

                if (navigator.appName == "Microsoft Internet Explorer") {
                    event.returnValue = false;
                }               
                return false;
            }
        }
    </script>



navigator.appName == "Microsoft Internet Explorer"  this is used because in ie 7 "e" is not supported so we used event in common for all ie versions...

Wednesday, September 5, 2012

$.ajax Method - Asynchronous postback

 $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'jisha','value1':'123456'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    }

                });

  data: "{'data':'jisha','value1':'123456'}" - the data is the parameter needed for the method.
here "data" and "value1" are the parameter names - should be same as the code behind parameter name.

each $.ajax function needs a post back. so total 5 post backs in the button btn click.
try and feel... lol..............

Look at the below button click function, i ve 5 post backs. bt the user does not feel even one.
Ajax made it all happen.

html code
*****************************************************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="sample.aspx.cs" Inherits="sample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#<%=txt.ClientID %>").keypress(function (e) {
                if (e.charCode == 44 || e.which == 44) {
                    if ($.browser.msie)
                        event.returnValue = false;

                    return false;
                }
            });

            $("#<%=btn.ClientID %>").click(function () {
                $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'chris','value1':'123456'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    }

                });
              
                $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'sonu','value1':'123456a'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    },
                    error: function (msg) {
                        alert(msg.responseText);
                    }

                });

                $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'golda','value1':'123456'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    }

                });

                $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'jisha','value1':'123456'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    }

                });

                $.ajax({
                    type: "POST",
                    url: "sample.aspx/ShowValue",
                    data: "{'data':'ramees','value1':'123456'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (msg) {
                        suc(msg);
                    }

                });

                return false;
            });
        });

        function suc(msg) {           
            var text = $("#divBody").html();
            $("#divBody").html(text + "<br/>" + msg.d);
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scr" runat="server" EnablePageMethods="true"></asp:ScriptManager>
        <div>
            <asp:TextBox ID="txt" runat="server"></asp:TextBox>
            <asp:Button ID="btn" runat="server" Text="Click" />
        </div>
        <div id="divBody"></div>
   
    </form>
</body>
</html>


*****************************************************************************

Code behind

*****************************************************************************
using System;
using System.Web.Services;

public partial class sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static string ShowValue(string data, int value1)
    {
        return DateTime.Now.ToString() + " " + data + " " + value1;
    }
}

*****************************************************************************

Disable or Remove Comma in Asp Textbox

we can disable comma using jquery.

The code is given below

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#<%=txt.ClientID %>").keypress(function (e) {
                if (e.charCode == 44 || e.which == 44) {
                    if ($.browser.msie)
                        event.returnValue = false;

                    return false;
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>




$("#<%=txt.ClientID %>").keypress(function (e) {
                if (e.charCode == 44 || e.which == 44) {
                    if ($.browser.msie)
                        event.returnValue = false;

                    return false;
                }
            });



 e.charCode == 44 || e.which == 44  ----------  this is used because IE 7 does not support e.charCode.
 and all the other browsers support e.charCode.

-----------------------------------------------------------------------
if ($.browser.msie)
                        event.returnValue = false;

                    return false;


 -------------------------------------------------------------------------

$.browser.msie is used to check whether the currunet browser is IE or not.
IE 7 does not support return false. dats why we used event.returnValue =false. 

Tuesday, September 4, 2012

Using Weather API in javascript

Yahoo, Google... etc are providing weather report through API's. We can directly use those in html page using jquery and javascript. we can use location id, or location sharing to get weather.

simply create one html file and use the code.
digg on this and find more exciting features.

here is the code.

-----------------------------------------------------------------------------------------------------------------------------

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <title></title>
    <script type="text/javascript">
        function loadXMLDoc() {
        
            var Result = $.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D%2233015%22&format=json", "",
    function (data) {
        display(data);
    });


        }
        function display(data) {
            $("body").html('');
            $("body").append("Sunrise: " + data.query.results.channel.astronomy.sunrise + "<br />");
            $("body").append("SuntSet: " + data.query.results.channel.astronomy.sunset + "<br />");
            $("body").append(data.query.results.channel.item.description + "<br />");
            $("body").append(data.query.results.channel.item.title + "<br />");
        }

    </script>
</head>
<body>
    <div id="myDiv">
        <h2>
            Get weather</h2>
    </div>
    <button type="button" onclick="loadXMLDoc()">
        Get weather</button>
</body>
</html>


-----------------------------------------------------------------------------------------------------------------------



$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D%2233015%22&format=json", "",
    function (data) {
        display(data);
    });

 this method returns a jason object. "data.query.results.channel". this contains more features. try digg on this.


you can share you location using the following code.

---------------------------------------------------------------------------------------------------------------
 if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(success, errorfn);
            }

 

 function success(position) {
            alert(position);
        }
        function errorfn(error) {

        }

---------------------------------------------------------------------------------------------------------------

some api's does not provide jason so we need to use this code

----------------------------------------------------------------------------------------------------------------

 if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "http://weather.yahooapis.com/forecastrss?w=615702&u=c", true);
            xmlhttp.send();

----------------------------------------------------------------------------------------------------------------------

Friday, August 31, 2012

Wednesday, August 22, 2012

Trigger

In a DBMS, a trigger is a SQL procedure that initiates an action (i.e., fires an action) when an event (INSERT, DELETE or UPDATE) occurs. Since triggers are event-driven specialized procedures, they are stored in and managed by the DBMS. A trigger cannot be called or executed; the DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion.
Each trigger is attached to a single, specified table in the database.
Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.


CREATE TRIGGER [dbo].[TrTermCondition] ON [dbo].[TermCondition]
FOR INSERT, UPDATE, DELETE
AS

DECLARE @VendorID AS INT

    IF EXISTS (SELECT 1 FROM INSERTED)
    BEGIN
        SELECT  @VendorID = VendorID                  
        FROM    INSERTED       
           
        UPDATE    BUYER
        SET        IsSalesTermsAccepted = 0,
                ModifiedDt = getDate(),
                ModifiedUserID = 55   
        FROM    Buyer B               
            INNER JOIN VendorBuyers VB ON VB.BuyerID = B.ID   
           
        WHERE    VB.VendorID = @VendorID                       
    END


Two special tables are used in trigger statements: the deleted table and the inserted table. Microsoft® SQL Server automatically creates and manages these tables. You can use these temporary, memory-resident tables to test the effects of certain data modifications and to set conditions for trigger actions; however, you cannot alter the data in the tables directly.
The inserted and deleted tables are used primarily in triggers to:
  • Extend referential integrity between tables.
  • Insert or update data in base tables underlying a view.
  • Check for errors and take action based on the error.
  • Find the difference between the state of a table before and after a data modification and take action(s) based on that difference.







Friday, August 17, 2012

Infosys launches unified cloud management solution



Infosys Technologies today launched a new solution -- Infosys Cloud Ecosystem Hub -- which will help companies manage their cloud applications and infrastructure through a single platform.

Cloud computing allows storage of data and access to software on a pay-per-use model, helping companies to cut costs as they do not have to invest in infrastructure.

"After 5-7 years, 60 per cent of the IT workload is expected to be on the cloud, which is a mix of public and private cloud. The solution is aimed to help companies manage fragmented IT environment, providing a unified platform and seamless experience," Infosys vice president and global head (cloud), Vishnu Bhat said.

Using the solution, businesses can accelerate time-to-market of cloud services by up to 40 per cent, improve productivity by up to 20 per cent and achieve cost-savings of up to 30 per cent, he added.


Read more

Wednesday, August 1, 2012

Piramid printing...

One of my friend asked me to do a homework 4 him, ie to display alphabets in a piramid mode like



I ve made a console application with the following codes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramContest
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.printFn();
        }

        private void printFn()
        {
            string[] ar = new string[] {"A","B","C","D","E","F" };

            int len = ar.Length - 1;
            while (!string.IsNullOrEmpty(ar[0]))
            {               
                foreach (string s in ar)
                {
                    Console.Write(s != string.Empty ? s : " ");
                }

                for (int i = ar.Length - 2; i >= 0; i--)
                {
                    Console.Write(ar[i] != string.Empty ? ar[i] : " ");
                }

                Console.Write(Environment.NewLine);
                ar[len] = string.Empty;
                len--;
            }

            Console.Write(Environment.NewLine);
            Console.Write(Environment.NewLine);
            Console.WriteLine("press any key to exit");
            ConsoleKeyInfo k= Console.ReadKey();
            if (k.ToString()!=string.Empty)
            {
                Environment.Exit(0);
            }
        }
    }
}