Hi All,
I am generating a PDF via x++ code and save it into a shared directory and once it's generated I tried to overwrite it and I could not because it is still being used by the AX , also I tried to delete the file but I can't due to same reason.
Please tell how I can achieve this.
Please see my below code :
public static void saveReport() { SysReportRun reportRun; filename mFile; QuotationId qId; Voucher custAcc; CustAccount custAccNum,loopNext; test_PrintDataCustPrcList testPr; tmp_InventTableModule tmpModule; pmf_PDFconditioner dynaPdf; str sFileName,adobeExe; testFinalReport testFinRep; pmf_DynaPrcList dynaPrcList; System.Diagnostics.Process process; System.Diagnostics.ProcessStartInfo processStartInfo; Args args = new Args(); boolean fileExists = false; PrintJobSettings pjs = new PrintJobSettings(); str path = "\\"+"\\pmfcgrb24\\temppricelistPDF"; #define.error("Error While Insert records in a table required to print Customer Price List") ; //winAPI::createDirectory(path); ttsbegin; delete_from testFinRep where testFinRep.CurUserId == XUserInfo::find(false, curUserId()).name; ttscommit; while select dynaPdf where dynaPdf.userName == XUserInfo::find(false, curUserId()).name { ttsbegin; delete_from dynaPrcList where dynaPrcList.UserName == XUserInfo::find(false, curUserId()).name; ttscommit; ttsbegin; dynaPrcList.UserName = XUserInfo::find(false, curUserId()).name; dynaPrcList.custAcc = dynaPdf.custAcc; dynaPrcList.insert(); ttscommit; select testPr where testPr.CurUserId == dynaPdf.userName && testPr.tmpCustAccount == dynaPdf.custAcc; { mFile = path+"\\"+"PioneerPriceList-"+testPr.tmpCustAccount+testPr.tmpCustName+".pdf"; sFileName = "PioneerPriceList-"+testPr.tmpCustAccount+testpr.tmpCustName; pjs.fileName(mFile); pjs.setTarget(PrintMedium::File); pjs.format(PrintFormat::PDF); pjs.preferredFileFormat(PrintFormat::PDF); pjs.warnIfFileExists(false); //args.name(reportstr("pmf_CustPrcListNewDesgn")); args.name(reportstr("pmf_CustPrcListNewDesgn_V1")); testFinRep = pmf_automateCustPrcList::loadPdfData(testPr.tmpCustAccount,testPr.CurUserId); args.record(testFinRep); reportRun = classFactory.reportRunClass(args); reportRun.printJobSettings(pjs.packPrintJobSettings()); reportRun.report().interactive(false); reportRun.init(); if (WinAPI::fileExists(mFile)) { fileExists = true; } if (!fileExists) { reportRun.run(); } /* try { ttsbegin; testFinRep.tmpCustName=testPr.tmpCustName; testFinRep.tmpCustAccount=testPr.tmpCustAccount; testFinRep.ItemId=testPr.ItemId; testFinRep.tmpItemName=testPr.tmpItemName; testFinRep.tmpItemGroupId=testPr.tmpItemGroupId; testFinRep.tmpExtItem=testPr.tmpExtItem; testFinRep.FilterDates=testPr.FilterDates; testFinRep.tmpNewPriceDate=testPr.tmpNewPriceDate; //testFinRep.CurUserId = XUserInfo::find(false, curUserId()).name; testFinRep.CurUserId = testPR.CurUserId; testFinRep.STDMinLineCharge = testPr.STDMinLineCharge; testFinRep.tmpMinLotCharge = testPr.tmpMinLotCharge; testFinRep.Division = testPr.Division; testFinRep.Price = testPr.Price; testFinRep.PriceUnit = testPr.PriceUnit; testFinRep.tmpPrice = testPr.tmpPrice; testFinRep.PriceDate = testPr.PriceDate; testFinRep.viewPrice = testPr.viewPrice; testFinRep.viewNewPrice = testPr.viewNewPrice; testFinRep.priceIncreaseDate = testPr.priceIncreaseDate; testFinRep.doNotPrintNewPrice = testPr.doNotPrintNewPrice; testFinRep.insert(); ttscommit; } catch { throw error(#error); }*/ } } }
All I want is I should be able to overwrite or delete the file.
Please help.
*This post is locked for comments