The method Create.NewTextNote of the Document class is the key to create a text node element. This sample code additionally gets the curve information of elements to align the text.
// Get the active document and view
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
View view = uiDoc.ActiveView;
foreach (Element elem in uiDoc.Selection.Elements)
{
// skip elements without curve
if (!(elem.Location is LocationCurve)) continue;
// get the curve of the element
Curve curve = ((LocationCurve)elem.Location).Curve;
// Calculate necessary auguments
XYZ origin = curve.get_EndPoint(0);
XYZ baseVec = XYZ.BasisX;
XYZ upVec = XYZ.BasisZ;
double textSize = curve.Length / 10;
double lineWidth = curve.Length / 50;
string strText = "This is " + elem.Name;
// Create the text
TextNote text = doc.Create.NewTextNote(view, origin,
baseVec,
upVec,
lineWidth,
TextAlignFlags.TEF_ALIGN_CENTER |
TextAlignFlags.TEF_ALIGN_MIDDLE, strText);
text.Width = curve.Length * 10; // set the width of the text
}