protected void CreateXML()
{
try
{
XmlDocument SettingsXML = new XmlDocument();
if (File.Exists(Server.MapPath(SettingsXMLPath)))
{
SettingsXML.Load(Server.MapPath(SettingsXMLPath));
XmlNodeList nodeXMLList = SettingsXML.SelectNodes("/UserGroups/Authentication");
XmlNode node = CreateNode(SettingsXML);
//Get reference to the book node and append the book node to it
XmlNode userGroupsNode = SettingsXML.SelectSingleNode("/UserGroups");
userGroupsNode.AppendChild(node);
}
else
{
XmlNode declarationNode = SettingsXML.CreateXmlDeclaration("1.0", "utf-8", "");
SettingsXML.AppendChild(declarationNode);
XmlNode userGroupsNode = SettingsXML.CreateElement("/UserGroups");
XmlNode node = CreateNode(SettingsXML);
userGroupsNode.AppendChild(node);
SettingsXML.AppendChild(userGroupsNode);
}
SettingsXML.Save(Server.MapPath(SettingsXMLPath));
if (Flag != "True")
{
lblMessage.Text = "User Registered Successfully.";
}
else
{
lblMessage.Text = "UserId already exists.";
}
txtUserId.Text = "";
txtPassword.Text = "";
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}
}
XmlNode CreateNode(XmlDocument doc)
{
XmlNode node = doc.CreateElement("Authentication");
XmlAttribute userIDAttribute = doc.CreateAttribute("UserID");
userIDAttribute.Value = Guid.NewGuid().ToString();
node.Attributes.Append(userIDAttribute);
//Add all the children of the node
XmlNode authType = doc.CreateElement("AuthType");
authType.InnerText = ddlUserType.SelectedValue;
node.AppendChild(authType);
XmlNode accessId = doc.CreateElement("AccessId");
accessId.InnerText = txtUserId.Text;
node.AppendChild(accessId);
XmlNode accessKey = doc.CreateElement("AccessKey");
accessKey.InnerText = txtPassword.Text;
node.AppendChild(accessKey);
XmlNode creationDate = doc.CreateElement("CreationDate");
creationDate.InnerText = DateTime.Now.ToLongDateString();
node.AppendChild(creationDate);
return node;
}
7:34 PM
Subscribe to:
Posts (Atom)