simple C# example

Questions and discussions on development tools for WarcraftRealms
Post Reply
rustane
Posts: 1
Joined: Thu Sep 29, 2005 2:40 am

simple C# example

Post by rustane »

this is what i do if your status.csv != myoldsavedstatus.csv .. if they are the same i just read the file i saved on the server. (checksum is the unix timestamp from the status file)

// This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25.
double timestamp = Convert.ToDouble(checksum);
// First make a System.DateTime equivalent to the UNIX Epoch.
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
// Add the number of seconds in UNIX timestamp to be converted.
dateTime = dateTime.AddSeconds(timestamp);

// The dateTime now contains the right date/time so to format the string,
// use the standard formatting methods of the DateTime object.
string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();

lblStatus.Text = "Got fresh guildinfo " + printDate;
TextWriter tw = new StreamWriter(Server.MapPath(@"\") + "status.txt");
tw.WriteLine(checksum2);
tw.Close();

string remoteUri = "http://www.warcraftrealms.com/exports/g ... did=154970";
string fileName = Server.MapPath(@"guildinfo.csv");
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
string myStringWebResource = remoteUri;
// Download the Web resource and save it into the folder.
myWebClient.DownloadFile(myStringWebResource,fileName);


string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath(@"\") + ";" +
"Extended Properties='text;HDR=Yes;FMT=Delimited'";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM guildinfo.csv", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();

objAdapter1.Fill(objDataset1, "XLData");

// Bind data to DataGrid control.
DataGrid1.DataSource = objDataset1;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();
DataBind();

Post Reply