Get Contact List from yahoo
July 2, 2009 at 8:40 am | In yahoo Contact List | Leave a Commentusing following code you can get contact list from any yahoo id.
using System;
using System.Collections.Specialized;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
public partial class YahooContact : System.Web.UI.Page
{
private const string _addressBookUrl = “http://address.yahoo.com/yab/us/Yahoo_ab.csv?loc=us&.rand=1671497644&A=H&Yahoo_ab.csv”;
private const string _authUrl = “https://login.yahoo.com/config/login?”;
private const string _loginPage = “https://login.yahoo.com/config/login”;
private const string _userAgent = “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3″;
private string username = string.Empty;
private string password = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
private ArrayList Extract(string uname, string upass)
{
bool result = false;
ArrayList myarray = new ArrayList();
//list = New MailContactList()
try
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
webClient.Encoding = Encoding.UTF8;
byte[] firstResponse = webClient.DownloadData(_loginPage);
string firstRes = Encoding.UTF8.GetString(firstResponse);
NameValueCollection postToLogin = new NameValueCollection();
Regex regex = new Regex(“type=\”hidden\” name=\”(.*?)\” value=\”(.*?)\”", RegexOptions.IgnoreCase);
Match match = regex.Match(firstRes);
while (match.Success)
{
if (match.Groups[0].Value.Length > 0)
{
postToLogin.Add(match.Groups[1].Value, match.Groups[2].Value);
}
match = regex.Match(firstRes, match.Index + match.Length);
}
postToLogin.Add(“.save”, “Sign In”);
postToLogin.Add(“.persistent”, “y”);
//Dim login As String = credential.UserName.Split(“@”c)(0)
string login = uname.Split(‘@’).GetValue(0).ToString();
postToLogin.Add(“login”, login);
postToLogin.Add(“passwd”, upass);
webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
webClient.Headers[HttpRequestHeader.Referer] = _loginPage;
webClient.Encoding = Encoding.UTF8;
webClient.Headers[HttpRequestHeader.Cookie] = webClient.ResponseHeaders[HttpResponseHeader.SetCookie];
webClient.UploadValues(_authUrl, postToLogin);
string cookie = webClient.ResponseHeaders[HttpResponseHeader.SetCookie];
//If String.IsNullOrEmpty(cookie) Then
//Return False
//End If
string newCookie = string.Empty;
string[] tmp1 = cookie.Split(‘,’);
foreach (string var in tmp1)
{
string[] tmp2 = var.Split(‘;’);
newCookie = (String.IsNullOrEmpty(newCookie) ? tmp2[0] : newCookie + “;” + tmp2[0]);
}
// set login cookie
webClient.Headers[HttpRequestHeader.Cookie] = newCookie;
byte[] thirdResponse = webClient.DownloadData(_addressBookUrl);
string thirdRes = Encoding.UTF8.GetString(thirdResponse);
string crumb = string.Empty;
Regex regexCrumb = new Regex(“type=\”hidden\” name=\”\\.crumb\” id=\”crumb1\” value=\”(.*?)\”", RegexOptions.IgnoreCase);
match = regexCrumb.Match(thirdRes);
if (match.Success && match.Groups[0].Value.Length > 0)
{
crumb = match.Groups[1].Value;
}
NameValueCollection postDataAB = new NameValueCollection();
postDataAB.Add(“.crumb”, crumb);
postDataAB.Add(“vcp”, “import_export”);
postDataAB.Add(“submit[action_export_yahoo]“, “Export Now”);
webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
webClient.Headers[HttpRequestHeader.Referer] = _addressBookUrl;
byte[] FourResponse = webClient.UploadValues(_addressBookUrl, postDataAB);
string csvData = Encoding.UTF8.GetString(FourResponse);
string[] lines = csvData.Split(‘\n’);
//Dim list1 As Hashtable()
foreach (string line in lines)
{
string[] items = line.Split(‘,’);
if (items.Length < 5)
{
continue;
}
string email = items[4];
string name = items[3];
if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(name))
{
email = email.Trim(‘”‘);
name = name.Trim(‘”‘);
if (!email.Equals(“Email”) && !name.Equals(“Nickname”))
{
MailContact mailContact = new MailContact();
mailContact.Name = name;
mailContact.Email = email;
myarray.Add(email);
//list.Add(mailContact)
}
}
}
result = true;
}
catch
{
}
return myarray;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
ArrayList contacts = new ArrayList();
StringBuilder sb = new StringBuilder();
contacts = Extract(txtusername.Text.Trim(), txtpassword.Text.Trim());
int j = 1;
for (int i = 0; i < contacts.Count; i++)
{
if (contacts[i].ToString().Trim() != “”)
{
sb.Append(“(” + j + “) ” + contacts[i].ToString() + “<br>”);
j++;
}
}
dvcontacts.InnerHtml = sb.ToString();
}
}
public class MailContact
{
private string _email = string.Empty;
private string _name = string.Empty;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Email
{
get { return _email; }
set { _email = value; }
}
public string FullEmail
{
get { return Email; }
}
}
AjaxPro.NET
June 24, 2009 at 5:58 am | In 1 | Leave a CommentAjaxPro.NET is a well-known open source framework, which is based on the server-side techniques and provides support for constructing different versions of .NET Web applications. The framework supports the server-side Its main functions are listed as below:
- Access the Session and Application data from the client-side JavaScript
- Cache the required results
- Freely use source code
- Add and modify new methods and properties in the framework without modifying any source code
- All the classes support the client-side JavaScript to return data, and DataSet can be used from inside the JavaScript
Use the HTML controls to access and return data - Do not need reload the pages and use the event delegate to access data
- Supply only one method for call and dramatically decrease the CPU usage
Learning about ASP.NET MVC
March 25, 2009 at 12:08 pm | In ASP.NET MVC | Leave a CommentToday i am sharing something Exciting about ASP.Net MVC ;Here’s a guide for learning about ASP.NET MVC.To Install ASP.NET MVC you need to install ASP.NET 3.5 version on your system.
The Model-View-Controller (MVC) is collection of three separates components: the model, the view, and the controller. The ASP.NET MVC framework provides an alternative way to creating MVC-based application; The MVC-Based applications are different from the ASP.NET Web Forms applications.MVC use all the existing features of ASP.Net Web application. The MVC framework is defined in the System.Web.Mvc namespace.
Understanding Models, Views, and Controllers:
Models for maintaining data and it help to implements the logic for the application. Retrieve and store state in the database, views for displaying all or a portion of the data, helps of applications user interface, and controllers for handling events that affect the model or view (s),and user nitration with the model. in short in an MVC application, the view only displays information; the controller handles and responds to user input and interaction.
The URL difference:
when we are using the ASP.net Web Forms application, then it should be correspondence between URL links and pages. But using MVC there is no correspondence between the address types in address bar and pages.
Creating sitemap:
The easiest way to create a Sitemap by creating an XML file that describes the navigational structure of your website. You can create a new Sitemap in Visual Studio by selecting the menu option Project, Add New Item, and add a Sitemap file.
The <sitemapnode> have the following attributes:
• URL
• Title
• Description
• Resourcekey
• Sitemapfile
e.g.
Web.sitemap
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode
url=”~/” title=”Home” description=”My Home Page”>
url=”~/Product/Index”
title=”Products”
description=”Our Products” />
url=”~/Service/Index”
title=”Services”
description=”Our Services” />
url=”~/Home/About”
title=”About”
description=”About Us” />
</siteMapNode> </siteMap>
Web.sitemap Sitemap API:
The Sitemap API is represents the static sitemap class. The access of the static site map class is anywhere within the MVC application. Static sitemap class helps to determine your current presence status. Static class has following properties:
• CurrentNode
• RootNode
• Childnode
• Description
• Nextsibling
• ParentNode etc
Advantages:
• MVC provides test-driven development (TDD) by default.
• Use all existing features of ASP.NET in ASP.NT MVC.
• Support URL naming patters for SEO.
Njoy Coding …………
Read Data From .txt File
February 17, 2009 at 4:30 am | In 1 | Leave a Commentcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
Boolean flag = false;
cmd = new SqlCommand();
cmd.CommandText = “SELECT ExecuteDate FROM ExecuteTab where ExecuteDate<=getdate() and PageCode=1″;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
flag = true;
}
con.Close();
if (flag)
{
string dd = “”;
string filetoread;
filetoread = Server.MapPath(“../Data/text.txt”);
StreamReader filestream;
filestream = File.OpenText(filetoread);
string readcontents;
readcontents = filestream.ReadToEnd();
readcontents = readcontents.Remove(0, 26);
char[] textdelimiter = { ‘|’, ‘\n’ };
string[] splitout = readcontents.Split(textdelimiter);
readcontents.Split(textdelimiter);
DataSet ds = new DataSet();
dcol = new DataColumn(“Col1″);
dt.Columns.Add(dcol);
dcol = new DataColumn(“Col2″);
dt.Columns.Add(dcol);
dcol = new DataColumn(“Col3″);
dt.Columns.Add(dcol);
dcol = new DataColumn(“Col4″);
dt.Columns.Add(dcol);
dcol = new DataColumn(“Col5″);
dt.Columns.Add(dcol);
long i;
try
{
for (i = 0; i < splitout.Length – 1; i = i + 6)
{
drow = dt.NewRow();
drow["Col1"] = splitout[i];
drow["Col2"] = splitout[i + 1];
drow["Col3"] = splitout[i + 2];
drow["Col4"] = splitout[i + 3];
drow["Col5"] = splitout[i + 4];
drow["Col6"] = splitout[i + 5];
dt.Rows.Add(drow);
}
}
catch (Exception exc)
{
}
filestream.Close();
StartThread();
}
Response.Redirect(“MyWebPage.aspx”);
}
public void StartThread()
{
T = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
T.Start();
}
private void Run()
{
foreach (DataRow rd in dt.Rows)
{
try
{
Boolean flage = false;
string address = “”;
cmd = new SqlCommand();
cmd.CommandText = “select num,Address+’,'+City+’,'+ Zip as Address from mytab where num=’” + rd[14].ToString() + “‘”;
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
flage = true;
address = dr["Address"].ToString();
}
con.Close();
if (flage)
{
cmd = new SqlCommand();
cmd.CommandText = “update mytab
set Col1=@ Col1, Col2=@ Col2, Col3=@ Col3, Col4=@ Col4, Col5=@ Col5 where num=’” + rd[14].ToString() + “‘”;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(“@Col1″, rd[0].ToString());
cmd.Parameters.Add(“@Col2″, rd[1].ToString());
cmd.Parameters.Add(“@Col3″, rd[2].ToString());
cmd.Parameters.Add(“@Col4″, rd[3].ToString());
cmd.Parameters.Add(“@Col5″, rd[4].ToString());
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
else
{
GoogleGeocoder.Coordinate coordinate = GoogleGeocoder.Geocode.GetCoordinates(address);
lat = coordinate.Latitude;
lon = coordinate.Longitude;
cmd = new SqlCommand();
cmd.CommandText = “INSERT INTO mytab
(Col1,Col2, Col3, Col4, Col5)VALUES (@Col1,@Col2, @Col3, @Col4, @Col5)”;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(“@Col1″, rd[0].ToString());
cmd.Parameters.Add(“@Col12″, rd[1].ToString());
cmd.Parameters.Add(“@Col3″, rd[2].ToString());
cmd.Parameters.Add(“@Col4″, rd[3].ToString());
cmd.Parameters.Add(“@Col5″, rd[4].ToString());
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
catch (Exception tt) { }
}
T.Suspend();
}
Mortgage Calculator
February 13, 2009 at 7:40 am | In Asp.Net Tricks | Leave a CommentToday i want to share with all of you how to create a Mortgage calculator to calculate Mortgage .
protected void Button1_Click(object sender, EventArgs e)
{
double result;
double loanprincipal;
double Downpayment;
double MortgagePrincipal;
int loanYears;
double loanInterest;
loanprincipal = Convert.ToDouble(txtAmount.Text);
Downpayment = Convert.ToDouble(txtDownpayment.Text);
loanYears = Convert.ToInt16(txtYears.Text);
loanInterest = Convert.ToDouble(txtRate.Text);
MortgagePrincipal = loanprincipal – Downpayment;
double totalpay = (loanYears * 12);
result = Convert.ToDouble(CalcLoan(MortgagePrincipal, loanYears, loanInterest));
lbPayment.Text = “”;
lbPrincipal.Text = “”;
LbResult.Text = “”;
lbPrincipal.Text = Convert.ToString(MortgagePrincipal);
lbPayment.Text = Convert.ToString(totalpay);
double Tresult= Convert.ToDouble(result);
LbResult.Text=String.Format(“{0:$#,##0.00;($#,##0.00);Zero}”, Tresult);
}
public double CalcLoan(double MortgagePrincipal, int loanYears, double loanInterest)
{
double loanMi = (loanInterest / 1200);
int numMonths = loanYears * 12;
double negNumMonths = 0 – numMonths;
double monthlyPayment = MortgagePrincipal * loanMi / (1 - System.Math.Pow((1 + loanMi), negNumMonths));
double totalPayment = monthlyPayment ;
return (monthlyPayment);
}
Set the width of File Upload Control
February 12, 2009 at 8:18 am | In General Controls | Leave a CommentTo set the width of File Upload Control on firefox need to set “Size” property.
<asp:FileUpload ID=”FileUpload1″ size=”1%” runat=”server” Font-Size=”Small”/>
Show Image on Crystal Report from Database
February 11, 2009 at 10:12 am | In Crystal Report image | Leave a Comment
To show image on Crystal Report from database you need to take a image field , save image in it by using the following code
Step 1)
string name = filename.PostedFile.FileName.ToString();//get file name as per your requirment
string strFn = path ;//your image path
FileInfo fiImage = new FileInfo(strFn);
Int32 len =Convert.ToInt32(fiImage.Length);
byte[] m_barrImg = new byte[Convert.ToInt32(len )];
FileStream fs = new FileStream(strFn, FileMode.Open,
FileAccess.Read, FileShare.Read);
int iBytesRead = fs.Read(m_barrImg, 0, Convert.ToInt32(len));
fs.Close();
byte[] imageData = ReadFile(path);
objpro.Logo1=(object)m_barrImg;///your image here save it in database(I m assinging it to property)
objpro.LogoName=Imagename;//image name
Step 2)
///now to show image on crystal report
Place this image field on your report by drag & drop.
Step 3) //where report will show e.g. it may be default.aspx
// I assume you have values in dataset ds;
Int32 Total=0;
Total = Convert.ToInt32(ds.Tables[0].Rows.Count.ToString());
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataRow drow;
dt.Columns.Add(“Image”, System.Type.GetType(“System.Byte[]“));
drow = dt.NewRow();
FileStream fs;
BinaryReader br;
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + “/CompanyLogo/” + TicketName))
{
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + “/CompanyLogo/” + TicketName, FileMode.Open);
}
else
{
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + “/CompanyLogo/logo.png”, FileMode.Open);
}
br = new BinaryReader(fs);
byte[] imgbyte = new byte[fs.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
drow[0] = imgbyte;
dt.Rows.Add(drow[0]);
br.Close();
fs.Close();
ReportDocument report = new ReportDocument();
string reportPath2 = Server.MapPath(“myRpt.rpt”);//your Report Name here
report.Load(reportPath2);
if (Total != 0)
{
report.SetDataSource(dt);
CrystalReportViewer1.ReportSource = report;
}
Creating .PDF File using Database Fields
February 10, 2009 at 9:09 am | In File Creation | Leave a Comment
try
{
Rectangle pageSize = new Rectangle(900, 900);
Document doc = new Document(pageSize);
PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + “\\Reports\\CustomReports\\AllReports\\” + ReportTitile + “.pdf”, FileMode.Create));
HeaderFooter footer = new HeaderFooter(new Phrase(“Page “), new Phrase(“.”));
footer.Border = Rectangle.NO_BORDER;
footer.Alignment = HeaderFooter.ALIGN_RIGHT;
doc.Footer = footer;
doc.Open();
iTextSharp.text.Table table = new iTextSharp.text.Table(7);
table.BorderWidth = 1;
// table.BorderColor = new Color(0, 0, 255);
table.Padding = 3;
table.Spacing = 1;
Cell cell = new Cell(” Report Title – “ + ReportTitile);
cell.Colspan = 7;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
cell.Colspan = 7;
cell.BackgroundColor = new Color(200, 200, 200);
string Col1 = “”, Col2 = “”, Col3 = “”, Col4 = “”, Col5 = “”, Col6 = “”, Col7 = “”;
try
{
Col1 = ddlCol1.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col2 = ddlCol2.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col3 = ddlCol3.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col4 = ddlCol4.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col5 = ddlCol5.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col6 = ddlCol6.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
try
{
Col7 = ddlCol7.SelectedItem.Text.ToString();
}
catch (Exception qqq) { }
Cell cell2 = new Cell(Col1);
table.AddCell(cell2);
Cell cell3 = new Cell(Col2);
table.AddCell(cell3);
Cell cell4 = new Cell(Col3);
table.AddCell(cell4);
Cell cell5 = new Cell(Col4);
table.AddCell(cell5);
Cell cell6 = new Cell(Col5);
table.AddCell(cell6);
Cell cell7 = new Cell(Col6);
table.AddCell(cell7);
Cell cell8 = new Cell(Col7);
table.AddCell(cell8);
cell2.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Linen);
cell3.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Linen);
cell4.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Linen);
cell5.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Linen);
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
cell3.HorizontalAlignment = Element.ALIGN_CENTER;
cell3.VerticalAlignment = Element.ALIGN_MIDDLE;
cell4.HorizontalAlignment = Element.ALIGN_CENTER;
cell4.VerticalAlignment = Element.ALIGN_MIDDLE;
cell5.HorizontalAlignment = Element.ALIGN_CENTER;
cell5.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Header = true;
try
{
for (int ii = 0; ii < total; ii++)
{
try
{
cell = new Cell(ds.Tables[0].Rows[ii][objpro.column1].ToString());
}
catch (Exception qww) { }
cell.BorderColor = new Color(255, 0, 0);
table.AddCell(cell);
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column2].ToString());
}
catch (Exception qww)
{
table.AddCell(” “);
}
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column3].ToString());
}
catch (Exception qww) { table.AddCell(” “); }
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column4].ToString());
}
catch (Exception qww) { table.AddCell(” “); }
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column5].ToString());
}
catch (Exception qww) { table.AddCell(” “); }
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column6].ToString());
}
catch (Exception qww) { table.AddCell(” “); }
try
{
table.AddCell(ds.Tables[0].Rows[ii][objpro.column7].ToString());
}
catch (Exception qww) { table.AddCell(” “); }
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
}
}
catch (Exception qqq)
{
}
doc.Add(table);
doc.Close();
}
catch (System.Exception qqq) { }
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.