AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 how to save the login time and logout time in text file using asp.net with c# with sql server
Posted by charan on  3/16/2010 3:36:03 AM Category: ADO.NET
Add to my favorites
Email to friend
hi i have table fields in sql server 2000

username nvarchar
password nvarchar

logintime datetime
logouttime datetime
hoursspend int


i want to save into text file when ever user login and logout any no of times and finally i want to know how many hours he spend in a day. can you give me a example which helps me

Post Your Reply Post New Question

 Viewer's Reply
Create, Write and Append Text in Files with Asp.Net
Answered By Moderator1 on 3/20/2010 10:54:55 PM
Hi,

I hope you know how to retrieve those login information from the database. You need to keep the details as a DataTable Rows. Then for creating a Text File and writing the content into it follow the code below,

string strFilePath = Server.MapPath(@".\LoginLog.txt");

using (StreamWriter sw = new StreamWriter(strFilePath, true))
{
sw.WriteLine("User Name: " + dr["UserName"].ToString());
sw.WriteLine("Login Time: " + dr["LoginTime"].ToString());
sw.WriteLine("Logout Time: " + dr["LogoutTime"].ToString());
sw.Close();
sw.Dispose();
}

To calculating the Hours spend, write you own logic.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview
Washington Technology
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!