Archive for the ‘XML’ Category

Signing an XML

Posted: October 10, 2008 in XML

public void sign()
{
XmlDocument doc = new XmlDocument();
doc.Load(@”C:\Inetpub\wwwroot\NumberVerfication\NumberVerification.xml”);

SignedXml signer = new SignedXml(doc);
RSA key = new RSACryptoServiceProvider();

signer.KeyInfo = new KeyInfo();
signer.KeyInfo.AddClause(new RSAKeyValue(key));
signer.SigningKey = key;

Reference orderRef = new Reference(“”);
orderRef.AddTransform(new XmlDsigEnvelopedSignatureTransform());

signer.AddReference(orderRef);
signer.ComputeSignature();

doc.DocumentElement.AppendChild(signer.GetXml());
txtOutput.Text = doc.InnerText;
doc.Save(@”E:\Numberverification.xml”);
}

This method will give the signed XML. This uses RSA Crtytography Algorithm.

Advertisements

Reading Data from XML

Posted: October 10, 2008 in XML

public string GetElementValue(string strElementName)
{
reader = new XmlTextReader(@”C:\Inetpub\wwwroot\NumberVerfication\NumberVerification.xml”);
Boolean flag = false;
string strElementValue = String.Empty;
while (reader.Read())
{
if (reader.LocalName == strElementName)
{
reader.Read();
strElementValue = reader.Value;
reader.Read();
flag = true;
}
}
if (flag == false)
{
return null;
}
else
return strElementValue;
}

Here i/p for themethod strElementName is the tag name in the xml for which the value has to be read.


public string GeUserAttributeValue(SPList listCollection, string attributeName,string userName)
{
if (userName == null)
{
userName = this.web.CurrentUser.Name;
}
for (int count = 0; count
}

break;
}
}
return strDeptName;
}

“z”, “#RowsetSchema is the namespace used in the XML and hence we add it to the namespace manager.
ows_Department is the name of field in XML for the Department field in the list.