Monday, August 29, 2011

Upload data files in a folder

--------------------------------
if (Directory.Exists(TextBox1.Text))
{
filePaths = Directory.GetFiles(TextBox1.Text);

foreach (string filepath in filePaths)
{
filename = Path.GetFileName(filepath);
dt = File.GetCreationTime(filepath);

cmd = new SqlCommand("select count(*) from Date where File_Name = '" + date + " " + filename + "'", con);

int userCount = (int)cmd.ExecuteScalar();
Label1.Text = userCount.ToString();
if (Label1.Text == "0")
{
datefn();
pathinsert = filepath;
pathinsert = pathinsert.Replace("\\", "/");
insertdata();
ListBox1.Items.Add(filename);
Label8.Text = "Total files added are " + ListBox1.Items.Count.ToString() + " and newly added files have been listed below";
}

}

}


protected void datefn()
{
cmd = new SqlCommand("insert into Date (File_Name,Date_Modified) values('" + date + " " + filename + "','" + dt + "')", con);
cmd.ExecuteNonQuery();
}
protected void insertdata()
{
try
{
// cmd = new SqlCommand("LOAD DATA LOCAL INFILE '" + pathinsert + "' INTO TABLE echi_db FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'", con);

cmd = new SqlCommand("BULK INSERT tabname FROM '" + pathinsert + "' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )", con);
cmd.CommandTimeout = 60000;
cmd.ExecuteNonQuery();


filename = " " + filename;
cmd = new SqlCommand("update db set FileName='" + date + filename + "' where len(FileName)=1", con);
cmd.CommandTimeout = 60000;
cmd.ExecuteNonQuery();


}
catch
{

}
}

Count variable using AJAX Timer Control

------------------------------
int Counter = 60;
int i;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Counter"] = Counter;
}

}


protected void Timer1_Tick(object sender, EventArgs e)
{
i = (int)ViewState["Counter"];

if (i == 0)
{
i = Convert.ToInt32(TextBox1.Text);
ViewState["Counter"] = i;
fileread();

}
else
{
i--;
ViewState["Counter"] = i;

}
Label6.Text = "Time left to refresh : " + ViewState["Counter"].ToString();
}

Wednesday, August 24, 2011

Link for Sample files in .NET

---------------------------

https://skydrive.live.com/?cid=2c5f5b0560e374cb&id=2C5F5B0560E374CB!130

Tuesday, August 23, 2011

Process Kill using .NET

------------------------------------

foreach (Process clsProcess in Process.GetProcesses())
{
string concheck = clsProcess.ToString();

clsProcess.Kill();

}

Execute command prompt in .NET

-----------------------------------
using System.Diagnostics;

System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;

cmd = new MySqlCommand("select * from table", con);
dr=cmd.ExecuteReader();
while (dr.Read())
{
path = dr["Fileloc"].ToString();

string[] words = path.Split(new Char[] { '\\' });
drive = words[0];
filename = words[1];

si.StartInfo.WorkingDirectory = drive + "\\";
si.StartInfo.Arguments = "/c " + filename;

si.Start();
string output = si.StandardOutput.ReadToEnd();

error_lbl.Text += si.StandardError.ReadToEnd()+"\n";
si.Close();

}
dr.Close();

Wednesday, August 3, 2011

Chart using ASP.NET

---------------------

using System.Web.UI.DataVisualization.Charting;

ArrayList yVal_Overall = new ArrayList();
ArrayList xVal_Overall = new ArrayList();
overallcmd = new SqlCommand("Select * from Customer", con);
overallrdr = overallcmd.ExecuteReader();
while (overallrdr.Read())
{
agentname = overallrdr["Col1"].ToString();
overallcount = Convert.ToInt32(overallrdr["Col2"]);
xVal_Overall.Add(agentname);
yVal_Overall.Add(overallcount);

}

overallrdr.Close();

Chart1.Series[0]["PieLabelStyle"] = "Inside";
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
Chart1.Titles.Add("Points of Failure");
Chart1.Series[0].Points.DataBindXY(xVal_Overall, yVal_Overall);


//if (overallcount > 2)
//{
// Chart1.Series[0].Points[0]["Exploded"] = "true";
// Chart1.Series[0].Points[1]["Exploded"] = "true";
// Chart1.Series[0].Points[2]["Exploded"] = "true";

Run exe using asp.net

-------------------
using System.Diagnostics;

string batchpath = @"C:\run.bat";
System.Diagnostics.Process.Start(batchpath);

//System.Diagnostics.Process si = new System.Diagnostics.Process();
//si.StartInfo.WorkingDirectory = "c:\\";
//si.StartInfo.UseShellExecute = false;
//si.StartInfo.FileName = "cmd.exe";
//si.StartInfo.Arguments = "/c notepad.exe";
//si.StartInfo.CreateNoWindow = true;
//si.StartInfo.RedirectStandardInput = true;
//si.StartInfo.RedirectStandardOutput = true;
//si.StartInfo.RedirectStandardError = true;
//si.Start();
//string output = si.StandardOutput.ReadToEnd();
//si.Close();
//Response.Write(output);

Facebook API with ASP.NET

Links
------

http://www.kennetham.com/2010/07/21/facebook-api-asp-net/

http://computerbeacon.net/downloads/