TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Thiyagarajan E
831
984
115k
Export to pdf from fastreport in mvc asp .net
Sep 27 2019 5:22 AM
Hi,
Please add the below code in the controller.
private
void
CreateDataSet()
{
// create simple dataset with one table
FDataSet =
new
DataSet();
DataTable table =
new
DataTable();
table.TableName =
"Employees"
;
FDataSet.Tables.Add(table);
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"Name"
,
typeof
(
string
));
table.Rows.Add(1,
"Andrew Fuller"
);
table.Rows.Add(2,
"Nancy Davolio"
);
table.Rows.Add(3,
"Margaret Peacock"
);
}
public
void
SaveMemoryStream(MemoryStream ms,
string
FileName)
{
FileStream outStream = System.IO.File.OpenWrite(FileName);
ms.WriteTo(outStream);
outStream.Flush();
outStream.Close();
}
[HttpPost]
public
JsonResult GetFile()
{
FastReport.Utils.Config.WebMode =
true
;
Report rep =
new
Report();
rep.Load(Request.PhysicalApplicationPath +
"App_Data/report.frx"
);
CreateDataSet();
rep.RegisterData(FDataSet);
if
(rep.Report.Prepare())
{
// Set PDF export props
FastReport.Export.Pdf.PDFExport pdfExport =
new
FastReport.Export.Pdf.PDFExport();
pdfExport.ShowProgress =
false
;
pdfExport.Subject =
"Subject"
;
pdfExport.Title =
"xxxxxxx"
;
pdfExport.Compressed =
true
;
pdfExport.AllowPrint =
true
;
pdfExport.EmbeddingFonts =
true
;
MemoryStream strm =
new
MemoryStream();
rep.Report.Export(pdfExport, strm);
rep.Dispose();
pdfExport.Dispose();
strm.Position = 0;
string
dateTime = DateTime.Now.ToString(
"yyyyddmmhhMMss"
) +
".pdf"
;
string
filePath = Server.MapPath(
"\\Content\\Downloads\\"
);
if
(!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
SaveMemoryStream(strm, filePath + dateTime);
//FileStream file = new FileStream("\\Content\\Downloads\\", FileMode.Create, FileAccess.Write);
//strm.WriteTo(file);
//file.Close();
// return stream in browser
return
Json(filePath + dateTime);
}
else
{
return
null
;
}
}
Thanks....
Reply
Answers (
0
)
Transfer a in-progress call twilio c#
c# ajax json web api mvc