The latest from Facebook: 'Open Stream API'
By Caroline McCarthy, CNET News.comTuesday, April 28, 2009 11:47 AM
A post on the Facebook developer blog announced the big application program interface (API) update from the social network, which it's calling the Open Stream API.
It's the first major implementation of an emerging (read: brand new) open standard called Activity Streams, on which Facebook has been collaborating with developers for the past few months.
Basically, what it means is that third-party developers will have access to a feed of all content posted to news feeds--notes, photos, videos, links, "likes" and comments, and activity from other applications built on the social network's platform.
http://www.zdnetasia.com/news/internet/0,39044908,62053619,00.htm?scid=nl_z_ntnd
Wednesday, April 29, 2009
Tuesday, April 28, 2009
SqlCommandBuilder Usage
SqlCommandBuilder Class
Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated SQL Server database. This class cannot be inherited.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx
You can use the SqlCommandBuilder to update the change to the adapter generated DataSet to database, and then call the following line
adapter.Update(dataSet, tableName);
Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated SQL Server database. This class cannot be inherited.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx
You can use the SqlCommandBuilder to update the change to the adapter generated DataSet to database, and then call the following line
adapter.Update(dataSet, tableName);
Friday, April 24, 2009
Tuesday, April 21, 2009
Export Database Table to Excel File
There are several methods to export Database Table to Excel file.
1. Export to Gridview and then to excel file
Code:
string style = @"<style> .text { mso-number-format:\@; } </style>";
GridView GridView1 = new GridView();
GridView1.RowDataBound += new GridViewRowEventHandler(gvUsers_RowDataBound);
GridView1.DataSource = [YOUR DATASOURCE];
GridView1.DataBind();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[6].Attributes.Add("class", "text");
e.Row.Cells[7].Attributes.Add("class", "text");
}
}
2. DataTable to Excel File:
a. Perfect solution:
//Create the DataTable first
string physicPath = HttpContext.Current.Server.MapPath("./Files");
string fileName = Guid.NewGuid() + ".Xls"
String strExcelConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes'", physicPath+fileName);
DataTableToExcel(dt, strExcelConn);
Response.Clear();
Response.WriteFile(physicPath + fileName);
string httpHeader = "attachment;filename=output.xls";
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", httpHeader);
Response.Flush();
public void DataTableToExcel(DataTable dt, string connString)
{
int rows = dt.Rows.Count;
int cols = dt.Columns.Count;
StringBuilder sb = new StringBuilder();
sb.Append("CREATE TABLE ");
if (string.IsNullOrEmpty(dt.TableName)) dt.TableName = "Table1";
sb.Append(dt.TableName + " ( ");
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append(string.Format("[{0}] varchar,", dt.Columns[i].ColumnName));
else
sb.Append(string.Format("[{0}] varchar)", dt.Columns[i].ColumnName));
}
using (OleDbConnection objConn = new OleDbConnection(connString))
{
OleDbCommand objCmd = new OleDbCommand();
objCmd.Connection = objConn;
objCmd.CommandText = sb.ToString();
objConn.Open();
objCmd.ExecuteNonQuery();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO ");
sb.Append(dt.TableName + " ( ");
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append("[" + dt.Columns[i].ColumnName + "],");
else
sb.Append("[" + dt.Columns[i].ColumnName + "]) values (");
}
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append("@" + dt.Columns[i].ColumnName + ",");
else
sb.Append("@" + dt.Columns[i].ColumnName + ")");
}
objCmd.CommandText = sb.ToString();
OleDbParameterCollection param = objCmd.Parameters;
for (int i = 0; i < cols; i++)
{
param.Add(new OleDbParameter("@" + dt.Columns[i].ColumnName, OleDbType.VarChar));
}
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < param.Count; i++)
{
param[i].Value = row[i];
}
objCmd.ExecuteNonQuery();
}
}
}
b. Non-perfect solution(File created does not comprise with the excel standard):
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
string sep = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(sep + dc.ColumnName);
sep = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
sep = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(sep + dr[i].ToString());
sep = "\t";
}
Response.Write("\n");
}
1. Export to Gridview and then to excel file
Code:
string style = @"<style> .text { mso-number-format:\@; } </style>";
GridView GridView1 = new GridView();
GridView1.RowDataBound += new GridViewRowEventHandler(gvUsers_RowDataBound);
GridView1.DataSource = [YOUR DATASOURCE];
GridView1.DataBind();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[6].Attributes.Add("class", "text");
e.Row.Cells[7].Attributes.Add("class", "text");
}
}
2. DataTable to Excel File:
a. Perfect solution:
//Create the DataTable first
string physicPath = HttpContext.Current.Server.MapPath("./Files");
string fileName = Guid.NewGuid() + ".Xls"
String strExcelConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes'", physicPath+fileName);
DataTableToExcel(dt, strExcelConn);
Response.Clear();
Response.WriteFile(physicPath + fileName);
string httpHeader = "attachment;filename=output.xls";
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", httpHeader);
Response.Flush();
public void DataTableToExcel(DataTable dt, string connString)
{
int rows = dt.Rows.Count;
int cols = dt.Columns.Count;
StringBuilder sb = new StringBuilder();
sb.Append("CREATE TABLE ");
if (string.IsNullOrEmpty(dt.TableName)) dt.TableName = "Table1";
sb.Append(dt.TableName + " ( ");
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append(string.Format("[{0}] varchar,", dt.Columns[i].ColumnName));
else
sb.Append(string.Format("[{0}] varchar)", dt.Columns[i].ColumnName));
}
using (OleDbConnection objConn = new OleDbConnection(connString))
{
OleDbCommand objCmd = new OleDbCommand();
objCmd.Connection = objConn;
objCmd.CommandText = sb.ToString();
objConn.Open();
objCmd.ExecuteNonQuery();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO ");
sb.Append(dt.TableName + " ( ");
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append("[" + dt.Columns[i].ColumnName + "],");
else
sb.Append("[" + dt.Columns[i].ColumnName + "]) values (");
}
for (int i = 0; i < cols; i++)
{
if (i < cols - 1)
sb.Append("@" + dt.Columns[i].ColumnName + ",");
else
sb.Append("@" + dt.Columns[i].ColumnName + ")");
}
objCmd.CommandText = sb.ToString();
OleDbParameterCollection param = objCmd.Parameters;
for (int i = 0; i < cols; i++)
{
param.Add(new OleDbParameter("@" + dt.Columns[i].ColumnName, OleDbType.VarChar));
}
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < param.Count; i++)
{
param[i].Value = row[i];
}
objCmd.ExecuteNonQuery();
}
}
}
b. Non-perfect solution(File created does not comprise with the excel standard):
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
string sep = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(sep + dc.ColumnName);
sep = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
sep = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(sep + dr[i].ToString());
sep = "\t";
}
Response.Write("\n");
}
Saturday, April 18, 2009
Templated ASP.NET User Controls
How to: Create Templated ASP.NET User Controls
http://msdn.microsoft.com/en-us/library/36574bf6(VS.80).aspx
ITemplate Interface
http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.aspxhttp://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein.aspx
Monday, April 13, 2009
Microsoft Web Platform
More than just a powerful set of tools, servers and technologies, the Microsoft Web Platform offers a complete ecosystem for building and hosting web sites, services, and applications. Whether you’re looking to build your company’s web presence or launch the next MySpace, we’ve got the products you need to be successful.
http://www.microsoft.com/web/default.aspx
http://www.microsoft.com/web/default.aspx
Monday, April 6, 2009
Use JSON.net to manipulate object
To serialize and deserialize JSON object.
I use the following library:
JSON.net 3.0:
http://james.newtonking.com/archive/2008/08/25/json-net-3-0-released.aspx
P.S.
In ASP.net 3.5, we can also use the following class:
system.web.script.serialization.javascriptserializer
PS2:
A new class called DataContractJsonSerializer can be used.
Friday, April 3, 2009
Ten ways to make your boss love you - and save your job
http://news.zdnet.com/2100-9595_22-284491.html
Subscribe to:
Posts (Atom)