Diễn đàn    ASP.NET & Sharepoint MOSS, WSS 2007    RDLC trên Aspnet v20, kết xuất PDF, hiện file PDF lập trình CS

Lập trình không biên giới

608  bài
7-8-2017 15:27:29
private void LoaiHoso()
{
MayinHelper en = new MayinHelper();
DataTable dt = en.ThongkeLoaiHoso();

// params
ReportParameter[] pars = en.loadParameters("loaihoso.txt");

// viewer
ReportDataSource repData = new ReportDataSource("DataSet1_DataTable1", dt);
repViewer.LocalReport.DataSources.Clear();
repViewer.LocalReport.ReportPath = Server.MapPath("/mod/hoso/rdlc/loaihoso.rdlc");
repViewer.LocalReport.SetParameters(pars);
repViewer.LocalReport.DataSources.Add(repData);
repViewer.LocalReport.Refresh();
}

pars phải cho vào trước "Add(repData);"

Theo đúng thứ tự như code trên.
DataTable1 thì có tên các cột là Column1, Column2, Column3, ....
 

Lập trình không biên giới

608  bài
7-8-2017 15:30:29
Nếu chỉ add toàn (Report) Parameter thì đơn giảng hơn :

// params
MayinHelper en = new MayinHelper();
ReportParameter[] pars = en.fillParameters(p);

// viewer
repViewer.LocalReport.ReportPath = Server.MapPath("/mod/hoso/rdlc/ltr2.rdlc");
repViewer.LocalReport.SetParameters(pars);
repViewer.LocalReport.Refresh();
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 

Lập trình không biên giới

608  bài
7-8-2017 15:31:53
Kết xuất RDLC ra file Pdf :

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;

byte[] bytes = repViewer.LocalReport.Render(
"PDF", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
string f_name = DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".pdf";
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(f_name), System.IO.FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();

Cái này quan trọng, khó kiếm trên mạng internet. Links ở đây :

https://msdn.microsoft.com/en-us/library/ms251839(VS.80).aspx

Mình tìm mất 2h trên google
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 

Lập trình không biên giới

608  bài
7-8-2017 19:5:16


Trên Firefox PDF Viewer không hiện tiếng việt. Nhưng mở bằng TWINUI của Win 8.1 thì hiển thị chữ tiếng việt bình thường.



Thế nên để mở file từ TWINUI code như sau :

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;

byte[] pdfContent = repViewer.LocalReport.Render(
"PDF", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);

string f_name = DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".pdf";

Response.Clear();
Response.Buffer = true;
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + f_name + "." + extension);
// response.ContentType = "application/pdf";
Response.BinaryWrite(pdfContent);
Response.Flush();
Response.End();
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM