我在我的网站上生成关于员工的不同类型报告。发布后它无法生成清楚。如果任何情况下它不生成结果,则消息将生成它没有结果值。发表后没有得到。在本地服务器上工作正常。我在下面给出我的代码。我不知道为什么这不能正常工作。如何为所有访问(客户端)机器设置路径。
我的代码在这里。
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); //base font
Font font = new Font(bfTimes, 8, Font.BOLD); //Header File
Font font1 = FontFactory.GetFont(FontFactory.TIMES, 7); //DateBase value
Font font2 = FontFactory.GetFont(FontFactory.TIMES, 7); //sub headings
DataTable dt = new DataTable();
DataSet ds = new DataSet();
DataTable dt2 = new DataTable();
DataSet ds2 = new DataSet();
Document doc = new Document(new Rectangle(570f, 600f));
// string path = Server.MapPath("~/Computer/F/reports/");
//PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"F:\\reports\\" + "Employeebloodreportsectionwise.pdf", FileMode.Create));
//PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(FilePath, FileMode.Create));
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
PdfPCell cell = null;
Phrase phrase = null;
PdfPTable table = new PdfPTable(8);
//table.SetTotalWidth(new float[] { 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f, 40f ,40f});//column width
table.SetTotalWidth(new float[] {
40f, 100f, 120f, 100f, 100f, 70f, 100f, 75f
}); //column width
PdfPTable table2 = new PdfPTable(2);
table2.TotalWidth = 520f;
table2.LockedWidth = true;
table2.HorizontalAlignment = 0;
table.TotalWidth = 520f; //table size
//fix the absolute width of the table
table.LockedWidth = true;
//relative col widths in proportions - 1/3 and 2/3
//table.SetWidths(widths);
table.HorizontalAlignment = 0;
//leave a gap before and after the table
table.SpacingBefore = 10f; //both are used to mention the space from heading
table.SpacingAfter = 20f;
string imageURL = Server.MapPath(".") + "/companylogo.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
//Resize image depend upon your need
jpg.ScaleToFit(110f, 100f);
//Give space before image
jpg.SpacingBefore = 10f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_LEFT;
doc.Add(jpg);
qry = "select CompanyName,Phone1,Address1,State,District from Company";
dr = conn1.query(qry);
if (dr.Read()) {
string company1 = dr[0].ToString();
Font times = new Font(bfTimes, 9, Font.BOLD, BaseColor.RED);
Paragraph p = (new Paragraph("" + company1 + "", times));
p.Alignment = Element.ALIGN_CENTER;
doc.Add(p);
string Address = dr[2].ToString();
string dist = dr[4].ToString();
string state1 = dr[3].ToString();
Font times1 = new Font(bfTimes, 7);
Paragraph p1 = (new Paragraph("Address:" + Address + "," + state1 + "," + dist + "", times1));
p1.Alignment = Element.ALIGN_CENTER;
doc.Add(p1);
string phone = dr[1].ToString();
//Font times1 = new Font(bfTimes, 10);
Paragraph p7 = (new Paragraph("PH:" + phone + "", times1));
p7.Alignment = Element.ALIGN_CENTER;
doc.Add(p7);
Font times2 = new Font(bfTimes, 8, Font.BOLD);
Paragraph p2 = (new Paragraph(" Department Wise Gender Report", times2));
p2.Alignment = Element.ALIGN_CENTER;
doc.Add(p2);
Paragraph p8 = (new Paragraph("Department:" + dddept.SelectedItem.Text + "", times1));
p8.Alignment = Element.ALIGN_CENTER;
doc.Add(p8);
cell = new PdfPCell(new Phrase("Sl.no", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Emp Code", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Name", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
//cell = new PdfPCell(new Phrase("Department", font));
//cell.HorizontalAlignment = Element.ALIGN_LEFT;
//table.AddCell(cell);
cell = new PdfPCell(new Phrase("Section", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Designation", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Dob", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Place", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Mobile", font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
//cell = new PdfPCell(new Phrase("Blood Group", font));
//cell.HorizontalAlignment = Element.ALIGN_LEFT;
//table.AddCell(cell);
//qry = "select EmpCode from EmpDetails where StatusID=1";
//dt2 = conn1.gettable(qry);
//if (dt2.Rows.Count > 0)
//{
// foreach(DataRow row2 in dt2.Rows)
// {
// string code = Convert.ToString(row2["EmpCode"]);
qry = "select EmpCode,Name,DeptName,sectname,Desgname,convert(varchar(15),Dob,103)As Dob,Sex,Place,Mobile,Blood from View_EmpDetails where Blood='" + ddblood.SelectedItem.Text + "' and Deptid='" + dddept.SelectedItem.Value + "' And StatusID='1'";
dt = conn1.gettable(qry); {
if (dt.Rows.Count > 0) {
int slno = 1;
foreach(DataRow row in dt.Rows) {
cell = new PdfPCell(new Phrase("" + slno + "", font2));
table.AddCell(cell);
EmpCode = Convert.ToString(row["EmpCode"]);
cell = new PdfPCell(new Phrase("" + EmpCode + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
name = Convert.ToString(row["Name"]);
cell = new PdfPCell(new Phrase("" + name + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
//dept = Convert.ToString(row["DeptName"]);
//cell = new PdfPCell(new Phrase("" + dept + "", font2));
//cell.HorizontalAlignment = Element.ALIGN_LEFT;
//table.AddCell(cell);
sect = Convert.ToString(row["sectname"]);
cell = new PdfPCell(new Phrase("" + sect + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
string desig = Convert.ToString(row["Desgname"]);
cell = new PdfPCell(new Phrase("" + desig + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
string dob = Convert.ToString(row["Dob"]);
cell = new PdfPCell(new Phrase("" + dob + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
string place = Convert.ToString(row["Place"]);
cell = new PdfPCell(new Phrase("" + place + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
string mobile = Convert.ToString(row["Mobile"]);
cell = new PdfPCell(new Phrase("" + mobile + "", font2));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
slno++;
}
table2.DefaultCell.Border = PdfPCell.NO_BORDER;
table2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table2.AddCell(new Phrase("Department: " + dddept.SelectedItem.Text + "", times2));
table2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
table2.AddCell(new Phrase("Blood Group: " + ddblood.SelectedItem.Text + "", times2));
doc.Add(table2);
doc.Add(table);
DateTime today = System.DateTime.Today;
string today2 = today.ToString("dd/MM/yyyy");
Paragraph p6 = (new Paragraph("Genrated Date:" + today2 + "", times2));
p6.Alignment = Element.ALIGN_RIGHT;
doc.Add(p6);
//System.Diagnostics.Process.Start(@"F:\\reports\\" + "Employeebloodreportsectionwise.pdf");
System.Diagnostics.Process.Start(FilePath);
refresh();
} else {
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('No employees in selected blood group in this department ..!!');", true);
doc.Close();
}
doc.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=BloodGroupReport.pdf");
Response.Write(doc);
Response.Flush();
Response.End();
}