I need to attached XML file to File. I developed code for generate XML file and download. How is the possible way change that code to attached XML file to Files.
This is my code :
#region Action
public PXAction<PX.Objects.SO.SOOrder> Attach;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Attach")]
protected virtual IEnumerable attach(PXAdapter adapter)
{
// Use your favorite library to create XML file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null));
// Create root node of XML file
XmlNode rootNode = xmlDoc.CreateElement("GridData");
// Iterate rows of the DataView
foreach (SOLine dacRecord in Base.Transactions.Select())
{
// Create an XML Element to represent the DAC row
XmlNode xmlDACRecord = xmlDoc.CreateElement("DACRecord");
// Add desired DAC fields as child XML Elements of the DAC row XML element
XmlNode xmlDACField1 = xmlDoc.CreateElement("DACField1");
xmlDACField1.AppendChild(xmlDoc.CreateTextNode(dacRecord.InventoryID.ToString()));
xmlDACRecord.AppendChild(xmlDACField1);
XmlNode xmlDACField2 = xmlDoc.CreateElement("DACField2");
xmlDACField2.AppendChild(xmlDoc.CreateTextNode(dacRecord.TranDesc.ToString()));
xmlDACRecord.AppendChild(xmlDACField2);
// Adding XML DAC Record to XML root node
rootNode.AppendChild(xmlDACRecord);
}
// Adding XML root node to XML document
xmlDoc.AppendChild(rootNode);
// Redirect browser to XML file created in memory on server
throw new PXRedirectToFileException(new PX.SM.FileInfo(Guid.NewGuid()+
".xml",
null,
System.Text.Encoding.UTF8.GetBytes(xmlDoc.OuterXml)),
true);
return adapter.Get();
Best answer by tharinduweerasooriya90
View original