Wednesday, April 11, 2012

Configuring Apache for ASP.NET

ASP.NET hosting with Apache

The mod_mono Apache module is used to run ASP.NET applications within the Apache web server.
The mod_mono module runs within an Apache process and passes all the requests to ASP.NET applications to an external Mono process that actually hosts your ASP.NET applications. The external ASP.NET host is called "mod-mono-server" and is part of the XSP module.
To use this, you must download and install the mod_mono and xsp components of Mono. mod_mono contains the actual Apache module, and xsp contains the actual ASP.NET hosting engine, both are available from our download page.
See the mod_mono page for details on installation and configuration.

Thursday, April 5, 2012

convert image to base64


For this u need to download Html agility


protected void Page_Load(object sender, EventArgs e)
{
HtmlWeb htmlWeb = new HtmlWeb();
HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("http://www.fortunehotels.in/");
foreach (HtmlNode someNode in document.DocumentNode.SelectNodes("//img[@src]"))
{
if (someNode.Attributes.Contains("src"))
{
if (someNode.Attributes["src"].Value.EndsWith(".jpg"))
{
if (someNode.Attributes["src"].Value != "admin/UploadImage/summer-packages2010717138.jpg")
{
if (someNode.Attributes["src"].Value != "admin/UploadImage/101X108201243356.jpg")
{
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(someNode.Attributes["src"].Value);
string base64ImageString = ConvertBytesToBase64(data);
someNode.Attributes["src"].Value = "data:image/jpg;base64," + base64ImageString;
myImage.Src = "data:image/jpg;base64,"+base64ImageString;
}
document.Save("C:/Users/sandeep_2/Desktop/fortune.htm");
}
}
}
}
}
public string ConvertBytesToBase64(byte[] imageBytes)
{
return Convert.ToBase64String(imageBytes);
}

Wednesday, April 4, 2012

Calculate age in sql

DECLARE @date datetime, @tmpdate datetime, @years int, @months int, @days int SELECT @date = '09/03/1985'
--date in mm/dd/yy
SELECT @tmpdate = @date SELECT @years = DATEDIFF(yy, @tmpdate, GETDATE()) - CASE WHEN MONTH(@date) > MONTH(GETDATE()) THEN 1 ELSE 0 END SELECT @tmpdate = DATEADD(yy, @years, @tmpdate) SELECT @months = DATEDIFF(m, @tmpdate, GETDATE()) - CASE WHEN DAY(@date) > DAY(GETDATE()) THEN 1 ELSE 0 END SELECT @tmpdate = DATEADD(m, @months, @tmpdate) SELECT @days = DATEDIFF(d, @tmpdate, GETDATE()) SELECT @years AS Years, @months AS Months, @days as Days

Tuesday, April 3, 2012

Read Excel

Define File name in the appsetting



<appSettings>
<add key="class" value="server=.;database=Hcl;uid=sa;pwd=sa123"/>
<add key="filename" value="order.xlsx"/>
<add key="filecity" value="City.xls"/>
</appSettings>

Call the method on button click



protected void btnsearch_Click(object sender, EventArgs e)
{
string location = Server.MapPath("~/Excel_file/") + ConfigurationManager.AppSettings["filename"].ToString().Trim();
GetExcelData(location);
}

Define Method



public DataTable GetExcelData(string location)
{
OledbConnectionString = string.Empty;
string ext = Path.GetExtension(ConfigurationManager.AppSettings["filename"].ToString().Trim());
if (ext == ".xls")
{
OledbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + location + ";Extended Properties=Excel 8.0;";
}
else if (ext == ".xlsx")
{
OledbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + location + ";Extended Properties=Excel 12.0;";
}
else
{ }
OleDbConnection objConn = null;
objConn = new OleDbConnection(OledbConnectionString);
if (objConn.State == ConnectionState.Closed)
{
objConn.Open();
}

string query = "Select * From [Order Sheet$] Where rtrim(ltrim([Order No#]))=" + txtorderid.Text.ToString().Trim() + " and rtrim(ltrim([Email Id]))='" + txtemail.Text.Replace("'", " ").Replace("-", " ").ToString().Trim() + "' and rtrim(ltrim([Delivery Name]))='" + txtCname.Text.Replace("'", " ").Replace("-", " ").ToString().Trim() + "'";
OleDbCommand objCmdSelect = new OleDbCommand(query, objConn);
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
objAdapter.SelectCommand = objCmdSelect;
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset);
box.Visible = true;

try
{
if (objDataset.Tables[0] != null)
{
if (objDataset.Tables[0].Rows.Count == 0)
{
viewdetail.Visible = false;
GridView1.DataSource = objDataset.Tables[0];
GridView1.DataBind();
txtCname.Text = "";
txtemail.Text = "";
txtorderid.Text = "";
}
else
{
viewdetail.Visible = true;
GridView1.DataSource = objDataset.Tables[0];
GridView1.DataBind();
txtCname.Text = "";
txtemail.Text = "";
txtorderid.Text = "";
}

}
else
{
viewdetail.Visible = false;
}
}
catch (Exception ex)
{

}
finally
{
objCmdSelect.Dispose();
objConn.Close();
objConn.Dispose();

}
// objConn.Close();
return objDataset.Tables[0];

}