There is a concern while generating PDF using jsReport package and C# code. Pdf are getting generated perfectly but i can see some bunch of files getting created on the Server AppData folder. As i was testing this locally i found the files getting created on my local User AppData folder.
I think its not a good pratice to generate files that we don't need. And also these files are not getting cleared. All i want to know is that is there a way to get rid of files that are getting created on AppData floder.
Below is my code config and code shot, jsreport theam can you suggest how to clean up the appdata folder?
Packages details used.
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="jsreport.Binary" Version="1.10.0" />
<PackageReference Include="jsreport.Local" Version="1.1.2" />
</ItemGroup>
AppData is getting populated with junk data. See the screen shot below.
Actual file folder location after running below code
public static async Task<Tuple<byte[], string, string>> GeneratePDF_Local(string tmplContent, string headerTmpl, string footerTmpl, string content, string fileName, string headerHeight, string footerHeight)
{
try
{
var rs = new LocalReporting()
.KillRunningJsReportProcesses()
.UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();
var report = await rs.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Recipe = Recipe.PhantomPdf,
Engine = Engine.Handlebars,
Content = tmplContent,
Phantom = new Phantom
{
Header = headerTmpl,
Footer = footerTmpl,
Orientation = PhantomOrientation.Portrait,
Format = PhantomFormat.A4,
BlockJavaScript = false,
HeaderHeight = headerHeight,
FooterHeight = footerHeight
}
},
Data = content
});
using (var ms = new MemoryStream())
{
await report.Content.CopyToAsync(ms);
var base64OutputFile = ms.ToArray();
using (FileStream file = new FileStream("E:\\" + fileName + ".pdf", FileMode.Create, FileAccess.Write))
{
//byte[] bytes = new byte[file.Length];
await file.WriteAsync(base64OutputFile, 0, base64OutputFile.Length);
}
await rs.KillAsync();
return new Tuple<byte[], string, string>(base64OutputFile, fileName, FileFormats.ApplicationPdf);
}
}
catch { throw; }
}
Folder on which actual file getting saved see below sceeen