TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bafana mthivane
NA
10
2.7k
xml using c#
Jun 12 2014 3:05 AM
using System.IO;
using System.Xml;
using System.Xml.Linq;
private static XmlDocument logDocumentWrite;
private static XDocument logDocumentRead;
private static string logDocumentPath = @"C:\Users\General\Documents\Visual Studio 2012\Projects\WpfWensday\DataTier\ActivityLog.xml";
public static void CheckLog()
{
if (!File.Exists(logDocumentPath))
{
using (XmlWriter createFile = XmlWriter.Create(logDocumentPath))
{
createFile.WriteStartDocument();
createFile.WriteStartElement("ActivityLog");
createFile.WriteEndElement();
createFile.WriteEndDocument();
}
}
}
public static void LogAction(int intID, string strName, string strAction)
{
logDocumentWrite = new XmlDocument();
logDocumentWrite.Load(logDocumentPath);
XmlElement xmlParentElement;
xmlParentElement = logDocumentWrite.CreateElement("Activity");
XmlElement xmlChildElement;
xmlChildElement = logDocumentWrite.CreateElement("Action");
xmlChildElement.InnerText = strAction;
xmlParentElement.AppendChild(xmlChildElement);
xmlChildElement = logDocumentWrite.CreateElement("Date");
xmlChildElement.InnerText = DateTime.Now.ToShortDateString();
xmlParentElement.AppendChild(xmlChildElement);
xmlChildElement = logDocumentWrite.CreateElement("Time");
xmlChildElement.InnerText = DateTime.Now.TimeOfDay.ToString();
xmlParentElement.AppendChild(xmlChildElement);
xmlChildElement = logDocumentWrite.CreateElement("UserName");
xmlChildElement.InnerText = strName;
xmlParentElement.AppendChild(xmlChildElement);
xmlChildElement = logDocumentWrite.CreateElement("UserID");
xmlChildElement.InnerText = intID.ToString();
xmlParentElement.AppendChild(xmlChildElement);
logDocumentWrite.DocumentElement.InsertAfter(xmlParentElement, logDocumentWrite.DocumentElement.LastChild);
logDocumentWrite.Save(logDocumentPath);
}
public IEnumerable<object> RetrieveActions()
{
logDocumentRead = XDocument.Load(logDocumentPath);
var Activities = from activity in logDocumentRead.Root.Elements("Activity")
select new
{
EmployeeID = activity.Elements("UserID").First().Value,
EmployeeName = activity.Elements("UserName").First().Value,
Action = activity.Elements("Action").First().Value,
Date = activity.Elements("Date").First().Value,
Time = activity.Elements("Time").First().Value
};
return Activities.ToList();
}
}
Reply
Answers (
2
)
add using linq c#
Fixed Header in Gridview