Google Search

Thursday, September 10, 2009

Social Bookmarking Tool

Social Bookmark: is a method for Internet users to store, organize, search, and manage bookmarks of web pages on the Internet with the help of metadata, typically in the form of tags that collectively and/or collaboratively become a folksonomy. Folksonomy is also called social tagging, "the process by which many users add metadata in the form of keywords to shared content. (from Wikipedia)

I always used to wonder how people keep those Bookmarking links under their posts. After a bit of research I have made a small tool to generate the code:

SocialBookmark.exe

Well I confirm that it has no malware, virus etc :)

It can be used with Wordpress.com, blogger and all other blogs which support HTML editing.


Well how to do it:

1. Double click the SocialBookmark.exe
2. Enter the post name in the "Blog Name" field (I know I should make that "Post Name")
3. Enter the link of the post in "Blog Path" ( this is the http link of each post, Wordpress directly show it, blogger, you might need to Publish your post and again edit)
4. Click the Generate Button
5. Copy the code generated and put them at the bottom of the post (remember you need to be in "edit html" mode)

This is just the start, I will improve upon it. Feedbacks comments are always welcome.
Will be happy if you click on the google ads on the left :)

If you liked it, do click the following, same is what gets generated by the tool I made:



add to del.icio.us : add to furl : Digg it! : ma.gnolia: : Stumble It! : post to facebook : twit this : Technorati

Saturday, August 1, 2009

html DOM hide show form elements

Hi I am doing this for my reference and also it may help others, was searching for how to hide elements, take a scenario where we need to display a text box on selection of check box. the form element may be declared hidden by using the attribute: style="visibility:hidden" for ex. <input type="text" style="visibility:hidden">, we can call a function. following code may be used:

<html>
<head>
<script Language="javascript">
function check()
{
if(document.rfsform.appdev.checked==true)
{
document.rfsform.woatt.style.visibility='visible';
}
else
{
document.rfsform.woatt.style.visibility='hidden';
}
}
</script>
</head>
<body>
<form name="rfsform">
<input type="checkbox" name="appdev" onclick="javascript: check();">
show/hide:
<INPUT TYPE="text" NAME="woatt" style="visibility:hidden">
</form>
</body>
</html>

Thursday, June 26, 2008

Consuming HTTPS web service using c# and asp.net

I have been trying this for this for the whole past week and finally got a solution, what I was provided was a https wsdl file and had to consume it. I tried a lot in ASP and could not find any solution and came up with consuming the web service using .NET 2.0 using C# and asp.net

The webservice provided was something like this:
https://xx.xxx.xxx.xxx/test/services/sum?wsdl"

The main issue was to handle the certificates, if we use https.

Suppose you have a function sum which returns sum of two numbers if provided as parameters in the wsdl definition.

To start with create a new website in Visual Studio (select Framework 2.0 if using VS 2008).
Create a web reference. Go to Project>>Add Web Reference.
A new Window will open here give the https link i.e https://xx.xxx.xxx.xxx/test/services/sum?wsdl and press the GO button. You will get those Certificate pop ups, select OK and accept then you can see the all the function in the description.
Provide a name let it be "web.sumref" and click on AddReference button.
Now go to default.aspx.cs file.
Here add the namespace "using web.sumref"
To resolve the issue with Certificates you need to implement the a class that impements ICertificatePolicy interface. Using this class we can return true so that it accepts all certificates.
For this you need to use the namespace:
using System.Security.Cryptography.X509Certificates;
And you need to call the CheckValidationResult before you call the web service.

Here is the code for default.aspx.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using web.sumref;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Threading;
using System.IO;
using System.Text;
using System.Xml;
public partial class _Default : System.Web.UI.Page {

//create object for web service
SumWebService obj = new SumWebService();
protected void Page_Load(object sender, EventArgs e) {
ServicePointManager.CertificatePolicy = new MyCertificateValidation();
int sum=obj.sum(2,3);
Response.Write(sum.ToString());
}
public class MyCertificateValidation : System.Net.ICertificatePolicy{
//This class handles problems with certificates if ssl (https) is used
bool ICertificatePolicy.CheckValidationResult(ServicePoint srvPoint, X509Certificate cert, WebRequest request, int problem) {

return true;
// Accept all certificates
}
}

Wednesday, May 21, 2008

Working with Stored Procedure in ASP.NET

This article is regarding working with stored procedure, i.e call a stored procedure from a web application. Here we will call a stored procedure to insert data to one of the table in the database.
Step 1: Creating the stored procedure
I have SQL Express 2005 installed, you may need to download the SQL server Management Studio express from microsoft website. Open the Management Studio then create a new database lets say "test". Then create a new Table called "login" with the following columns:

id (primary key) varchar(50)

password varchar(50)

email varchar(50)

No go to "Programmability">>"Stored Procedure">>right click>>"New Stored Procedure"

Here following is the stored procedure to insert values to the table we just created:


CREATE PROCEDURE submitrecord
(
@id varchar(50),
@password varchar(50),
@email varchar(50)
)
AS
insert into login (id, password,email)values (@id,@password,@email)

and save it.


Step 2: Execute the stored procedure from web application
From the Visual Studio create a new Web Application let it be "storedproc"
Design the default.aspx as following:
Now in the default.aspx.cs should look like this:


using System;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataSet ds = new DataSet();
SqlConnection con;
SqlCommand cmd = new SqlCommand();
SqlParameter sp1 = new SqlParameter();
SqlParameter sp2 = new SqlParameter();
SqlParameter sp3 = new SqlParameter();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("Trusted_Connection=Yes;database=test;data source=.\SQLEXPRESS;");
con.Open();
cmd = new SqlCommand("submitrecord", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = txtId.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = txtpwd.Text;
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtemail.Text;
cmd.ExecuteNonQuery();
con.Close();
}
}


The code is self explainatory, and the main issue any person faces is with the connection string.

Tuesday, April 1, 2008

Ajax AutoCompleteExtender using Google Suggest API

Hi,

After a long time I am posting an article.

This is on the Ajax toolkits control called AutoCompleteExtender.

Here I am trying to make a google suggest like site, using the Google Suggest REST API.

The Page will somewhat look like this:



The autocomplete extender works on the textbox and uses a webservice method. You need to have a webform (default.aspx), a webservice (google.asmx). Follwoing is the default.aspx page:
NOTE: I have used VS 2005 with AJAX extention and AjaxControlToolkit. Create a new Ajax enabled website from VS 2005. The dfault.aspx has nothing but 1 textbox, and the associated autocompleteextender:

Google Suggest:
asp:TextBox ID="TextBox1" runat="server"
asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click"
cc1:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
Enabled="true"
MinimumPrefixLength="1"
TargetControlID="TextBox1"
ServicePath="google.asmx"
ServiceMethod="getList"
/cc1:AutoCompleteExtender
______________________________default.aspx___________________________



____________________________________________________________________ You may give the code for Button1_Click:

protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://www.google.co.in/search?hl=en&q=" + TextBox1.Text;
Response.Redirect(url);
}
____________________________________________________________
google.asmx has one method called the getList which returns an array fetched from the google suggest API.

_______________________google.asmx____________________________________


using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

///


/// Summary description for google
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class google : System.Web.Services.WebService
{
[WebMethod]
public string[] getList(String prefixText)
{
XmlDocument doc = new XmlDocument();
List suggArList = new List();
string url = "http://google.com/complete/search?output=toolbar&q=" + prefixText;
doc.Load(url);
foreach (XmlNode node in doc.SelectNodes("//CompleteSuggestion"))
{
string value = node.SelectSingleNode("suggestion/@data").InnerText;
suggArList.Add(value);
}
return suggArList.ToArray();
}
}
____________________________________________________________________

NOTE: there seems to be an issue when code behind system is used for the webservice, also we need to ensure that [System.Web.Script.Services.ScriptService] is called.





Wednesday, October 31, 2007

Realtime Cricket Scores using ASP.NET AJAX

This is the application I built using ASP.NET AJAX using the RSS feeds of CricInfo(dont know if it is legal).

The scores gets updated without you refreshing.

After you have installed the ASP.NET AJAX create a new ASP.NET AJAX Enabled Web site.

In the Default.aspx page:

Put a Script Manager control from the AJAX server controls

Then add an Update Panel control from the same AJAX server controls.

Inside Update Panel Add the following controls:

Timer (AJAX) (set the interval to 10000 (10 secs))
A gridView control (set the Visible property to false)
and two Labels(one showing current time, other one showing the score)

Note: All these should be inside a tag.

Now in the Page_Load of default.aspx.cs:


DataSet ds = new DataSet();
ds.ReadXml("http://www.cricinfo.com/rss/livescores.xml");
GridView1.DataSource = ds.Tables[2];
GridView1.DataBind();
lblTime.Text = DateTime.Now.ToString();
lblScore1.Text = GridView1.Rows[0].Cells[2].Text;

Double click the Timer control:
In the Timer1_Tick event:

lblTime.Text = DateTime.Now.ToString();
lblScore1.Text = GridView1.Rows[0].Cells[2].Text;

Monday, January 29, 2007

whoami

I am having a blog in wordpress(http://pabmohan.wordpress.com), thought letme have another one.
About me????

Well I am Pabitra Mohan, an Indian

Working in an Indian software company