Thursday, May 30, 2013

how to make text file from database and datatable to text file?

public static void makTextfile()
{
           
try
{
var lat = Convert.ToDouble(52.44752859573569);
var lng = Convert.ToDouble(-1.8621826171875);
DataTable dt = new DataTable();
SqlDataAdapter adap = new SqlDataAdapter("select productcode ='0',supplier=CompanyName,telphone = PhoneNumber,Address1,Address2,Address3,Address4,PostCode,websiteurl =website,lat =latitude,lng = longitude,distance = 0, addressc = Address1 from tblstockistdetails where PostCode != '' and latitude is not null ", cn);
adap.Fill(dt);
IEnumerable<dynamic> dd = null;
dd = dt.AsEnumerable();
IEnumerable<dynamic> ee = null;
ee = (from d in dd select d).ToList();
if (ee.Count() > 0)
{
var aa1 = (from p in ee.ToList()
select new
{
get1 = "<div style='font-family: Trebuchet MS; font-size: 11px;'><b><u>" + p["supplier"] + "</u></b><br>" +
(p["Address1"].Trim() == "" ? "" : ("<b>Address 1: </b>" + p["Address1"] + "<br>")) +
(p["Address2"].Trim() == "" ? "" : ("<b>Address 2: </b>" + p["Address2"] + "<br>")) +
(p["Address3"].Trim() == "" ? "" : ("<b>Address 3: </b>" + p["Address3"] + "<br>")) +
(p["Address4"].Trim() == "" ? "" : ("<b>Town : </b>" + p["Address4"] + "<br>")) +
(p["PostCode"].Trim() == "" ? "" : ("<b>Postcode : </b>" + p["PostCode"] + "<br>")) +
(p["telphone"].Trim() == "" ? "" : ("<b>Telephone : </b>" + p["telphone"] + "<br>")) +
"|" + p["lng"] + "|" + p["lat"]
}).ToList();
string res = aa1.Select(p => p.get1).Aggregate((s1, s2) => (s1 + " ~ " + s2));
string strpath1 = Config.PhyLogFileSTK;
System.IO.File.WriteAllText(strpath1, res.ToString());
}
}
catch (Exception ex)
{
      //         
}
           
}

No comments:

Post a Comment