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
Adhikar Patil
NA
481
128.3k
I want to change report title dynamically using local report
Mar 8 2020 12:56 PM
Hi,
I export a LocalReport to a PDF file, I use the LocalReport.Render(...) method, but the title of PDF is the
file name of the LocalReport.
If the LocalReport file is "NBISIAReport.rdlc", the title of PDF will be "NBISIAReport".
I want to define the title dynamically. Thanks an advance...
Here is My Code
[HttpPost]
public
ActionResult GenerateMultipleNBISIAReport(List<NBISIAReportViewModel> structures)
{
try
{
//var dirName = User.Identity.Name.Replace(" ", "");
DateTime currDate = DateTime.Now;
string
dirName =
"NBI-SIA_Reports"
+
"_"
+ currDate.ToString(
"MM"
) +
"_"
+ currDate.ToString(
"dd"
) +
"_"
+ currDate.ToString(
"yy"
) +
"_"
+ currDate.ToString(
"HH"
) +
"_"
+ currDate.ToString(
"mm"
);
var reportFolderPath = Request.MapPath(Request.ApplicationPath) +
"Downloads/"
+ dirName;
const
string
fileExtension =
"PDF"
;
var zipFolderPath = reportFolderPath +
"/"
+ dirName +
".zip"
;
var exists = Directory.Exists(reportFolderPath);
if
(!exists)
{
Directory.CreateDirectory(reportFolderPath);
}
else
{
Directory.Delete(reportFolderPath,
true
);
Directory.CreateDirectory(reportFolderPath);
}
foreach
(var structure
in
structures)
{
if
(structure.Id ==
null
)
continue
;
string
reportName;
string
reportPath;
string
reportTitle;
switch
(structure.StrKindCode)
{
case
"1"
:
reportPath = Request.MapPath(Request.ApplicationPath) + @
"Reports\NBISIAReport.rdlc"
;
reportName = structure.StrNumber +
"-Bridge.pdf"
;
break
;
case
"2"
:
reportPath = Request.MapPath(Request.ApplicationPath) + @
"Reports\NBISIAReport.rdlc"
;
reportName = structure.StrNumber +
"-Culvert.pdf"
;
break
;
case
"3"
:
reportPath = Request.MapPath(Request.ApplicationPath) + @
"Reports\NBISIAReport.rdlc"
;
reportName = structure.StrNumber +
"-Tunnel.pdf"
;
break
;
case
"4"
:
reportPath = Request.MapPath(Request.ApplicationPath) + @
"Reports\NBISIAReport.rdlc"
;
reportName = structure.StrNumber +
"-Trail.pdf"
;
break
;
default
:
reportPath = Request.MapPath(Request.ApplicationPath) + @
"Reports\NBISIAReport.rdlc"
;
reportName = structure.StrNumber +
"-Other.pdf"
;
break
;
}
var localReport =
new
LocalReport
{
ReportPath = reportPath
};
var obj =
new
InspectionReportData();
var ds = obj.GetNBISIAReportData(Convert.ToInt32(structure.Id), AgencyCode);
localReport.DataSources.Add(
new
ReportDataSource(
"NBISIAReportDataSet"
, ds.Tables[0]));
localReport.DataSources.Add(
new
ReportDataSource(
"NBISIABIPReportDataSet"
, ds.Tables[1]));
localReport.EnableExternalImages =
true
;
localReport.DisplayName=
'Bridge NBI SIA Report'
;
var renderByte = localReport.Render(fileExtension,
""
);
using
(var fileStream =
new
FileStream(reportFolderPath +
"/"
+ reportName, FileMode.Create))
{
fileStream.Write(renderByte, 0, renderByte.Length);
}
}
using
(var zip =
new
ZipFile())
{
zip.AddDirectory(reportFolderPath);
zip.Save(zipFolderPath);
}
dirName =
string
.Empty;
return
Json(
new
{ success =
true
, filePath = zipFolderPath }, JsonRequestBehavior.AllowGet);
}
catch
(Exception ex)
{
return
Json(
new
{ success =
false
, message = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
Reply
Answers (
9
)
How to call asp.net web api from View
Xamarin: Webview is not working for specific Http address