I am using below sample code to attach a excel file as attachment at record header level.
using OfficeOpenXml;
class RunnableClass1
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
TCMMassPrintingNoticeTable tabb;
str filename = "MyTest.xlsx";
select firstonly tabb where tabb.TransId == "AK-GA-000000004";
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
using (var package = new ExcelPackage(stream))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");
ExcelRange cell = worksheet.Cells.get_Item(1,1);
cell.Value = 'Record type';
package.Save();
}
var mime = System.Web.MimeMapping::GetMimeMapping(filename);
//File::SendFileToUser(stream, 'data.xlsx');
DocumentManagement::attachFileToCommon(tabb, "file", stream, fileName, mime, fileName);
}
}
}
Here "TCMMassPrintingNoticeTable" is the header table used in a custom form where I am attaching the excel file. the code creates and attaches a excel file but it is corrupted. Am I missing something or doing something wrong. Please suggest.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156