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
Narasiman nar
NA
64
22.2k
In Dev environment is working but in production is not work
May 24 2018 8:46 PM
The below code working in Dev environemt but in production shows error.
if
(filterCriteria ==
"2"
&& dataFormat ==
"3"
)
{
if
(!Directory.Exists(HttpContext.Current.Server.MapPath(
"~/"
) +
"reports"
))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(
"~/"
) +
"reports"
);
}
var fileName =
"FarmerReportsSurveyQuestions"
+ DateTime.Now.ToString(
"yyyy_MM_dd__hh_mm_ss"
) +
".xlsx"
;
var outputDir = HttpContext.Current.Server.MapPath(
"~"
) +
"\\reports\\"
;
var file =
new
FileInfo(outputDir + fileName);
try
{
using
(var package =
new
ExcelPackage(file))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(
"FARMER/FARM REPORTS"
);
worksheet.TabColor = Color.Green;
worksheet.DefaultRowHeight = 12;
worksheet.HeaderFooter.FirstFooter.LeftAlignedText =
string
.Format(
"Generated: {0}"
, DateTime.Now.ToShortDateString());
DataTable dtFarmerFarmReports = dal.DAL_GetFarmer_FarmReports_All_ForExcel(originname, hdnSeasonalYear.Value.ToString());
if
(dtFarmerFarmReports.Rows.Count > 0)
{
using
(var range = worksheet.Cells[2, 1, 2, 11])
{
range.Style.Font.Bold =
true
;
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Font.Color.SetColor(Color.Black);
range.Style.Fill.BackgroundColor.SetColor(Color.Green);
range.AutoFitColumns();
}
worksheet.Cells[
"A1:BZ1"
].Merge =
true
;
worksheet.Cells[
"A1:BZ1"
].Value =
"FARMER/FARM DATA"
;
worksheet.Row(1).Height = 35;
using
(var range = worksheet.Cells[1, 1, 1, 11])
{
range.Style.Font.Bold =
true
;
range.Style.Font.Size = 22;
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.LightSeaGreen);
range.Style.Font.Color.SetColor(Color.Black);
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
range.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
range.Style.ShrinkToFit =
false
;
}
worksheet.Cells[2, 1].Value =
"FARMER ID"
;
worksheet.Cells[2, 2].Value =
"NAME"
;
worksheet.Cells[2, 3].Value =
"SEASON"
;
worksheet.Cells[2, 4].Value =
"GENDER"
;
worksheet.Cells[2, 5].Value =
"DATE OF BIRTH"
;
worksheet.Cells[2, 6].Value =
"BIRTH LOCATION"
;
worksheet.Cells[2, 7].Value =
"PHOTO"
;
worksheet.Cells[2, 8].Value =
"FATHER NAME"
;
worksheet.Cells[2, 9].Value =
"MOTHER NAME"
;
worksheet.Cells[2, 10].Value =
"PHONE NUMBER"
;
worksheet.Cells[2, 11].Value =
"OBSERVATION"
;
worksheet.Cells[2, 12].Value =
"NO. OF FARMS"
;
worksheet.Cells[2, 13].Value =
"PRODUCTION ESTIMATION"
;
worksheet.Cells[2, 14].Value =
"REGION"
;
worksheet.Cells[2, 15].Value =
"DISTRICT"
;
worksheet.Cells[2, 16].Value =
"SUB DISTRICT"
;
worksheet.Cells[2, 17].Value =
"VILLAGE"
;
worksheet.Cells[2, 18].Value =
"SECTION"
;
worksheet.Cells[2, 19].Value =
"ZONE"
;
worksheet.Cells[2, 20].Value =
"LAST YEAR COOPERATIVE"
;
worksheet.Cells[2, 21].Value =
"CURRENT YEAR COOPERATIVE"
;
worksheet.Cells[2, 22].Value =
"FARMER OTHER DETAILS"
;
worksheet.Cells[2, 23].Value =
"FARM NO"
;
worksheet.Cells[2, 24].Value =
"FARM VISIT NO"
;
worksheet.Cells[2, 25].Value =
"FARM DETAILS"
;
worksheet.Cells[2, 26].Value =
"FARM PICTURE 1"
;
worksheet.Cells[2, 27].Value =
"FARM PICTURE 1 - LATITUDE"
;
worksheet.Cells[2, 28].Value =
"FARM PICTURE 1 - LONGITUDE"
;
worksheet.Cells[2, 29].Value =
"FARM PICTURE 1 - TIMESTAMP"
;
worksheet.Cells[2, 30].Value =
"FARM PICTURE 2"
;
worksheet.Cells[2, 31].Value =
"FARM PICTURE 2 - LATITUDE"
;
worksheet.Cells[2, 32].Value =
"FARM PICTURE 2- LONGITUDE"
;
worksheet.Cells[2, 33].Value =
"FARM PICTURE 2 - TIMESTAMP"
;
worksheet.Cells[2, 34].Value =
"FARM PICTURE 3"
;
worksheet.Cells[2, 35].Value =
"FARM PICTURE 3 - LATITUDE"
;
worksheet.Cells[2, 36].Value =
"FARM PICTURE 3 - LONGITUDE"
;
worksheet.Cells[2, 37].Value =
"FARM PICTURE 3 - TIMESTAMP"
;
worksheet.Cells[2, 38].Value =
"AREA IN SQ.METER"
;
worksheet.Cells[2, 39].Value =
"AREA IN HECTARE"
;
worksheet.Cells[2, 40].Value =
"DECLARED AREA"
;
worksheet.Cells[2, 41].Value =
"GPX AREA"
;
worksheet.Cells[2, 42].Value =
"AREA BALANCE"
;
worksheet.Cells[2, 43].Value =
"FIELD STAFF"
;
#region questions
int
columnindex = 43;
List<
string
> lst =
new
List<
string
>();
// declare "lst" here
foreach
(DataRow row
in
dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<
string
,
string
>>(row[
"farm_detailsdata"
].ToString());
string
str =
string
.Empty;
lst.AddRange(dict.Keys);
// add the keys inside your foreach
}
var distinctList = lst.Distinct().ToList();
// perform the Distinct outside the foreach
List<ExcelHeader> excelheaderlist =
new
List<ExcelHeader>();
foreach
(var data
in
distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
ExcelHeader excelHeader =
new
ExcelHeader
{
colIndex = columnindex,
colName = data
};
excelheaderlist.Add(excelHeader);
}
#endregion questions
for
(
int
j = 0; j < dtFarmerFarmReports.Rows.Count; j++)
{
int
j1 = (j + 3);
farmerid = dtFarmerFarmReports.Rows[j][
"farmer_id"
].ToString();
worksheet.Cells[(j1), 1].Value = dtFarmerFarmReports.Rows[j][
"farmer_id"
].ToString();
worksheet.Cells[(j1), 2].Value = dtFarmerFarmReports.Rows[j][
"farmer_name"
].ToString();
worksheet.Cells[(j1), 3].Value = dtFarmerFarmReports.Rows[j][
"farmer_season"
].ToString();
worksheet.Cells[(j1), 4].Value = dtFarmerFarmReports.Rows[j][
"gender"
].ToString();
worksheet.Cells[(j1), 5].Value = dtFarmerFarmReports.Rows[j][
"dateofbirth"
].ToString();
worksheet.Cells[(j1), 6].Value = dtFarmerFarmReports.Rows[j][
"birthlocation"
].ToString();
if
(dtFarmerFarmReports.Rows[j][
"farmerphoto"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farmerphoto"
].ToString() ==
null
|| dtFarmerFarmReports.Rows[j][
"farmerphoto"
].ToString() ==
"-"
)
{
worksheet.Cells[(j1), 7].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 7].Value =
"Click to view"
;
worksheet.Cells[(j1), 7].Hyperlink =
new
Uri(dtFarmerFarmReports.Rows[j][
"farmerphoto"
].ToString());
}
worksheet.Cells[(j1), 8].Value = dtFarmerFarmReports.Rows[j][
"fathername"
].ToString();
worksheet.Cells[(j1), 9].Value = dtFarmerFarmReports.Rows[j][
"mothername"
].ToString();
worksheet.Cells[(j1), 10].Value = dtFarmerFarmReports.Rows[j][
"phonenumber"
].ToString();
worksheet.Cells[(j1), 11].Value = dtFarmerFarmReports.Rows[j][
"observation"
].ToString();
worksheet.Cells[(j1), 12].Value = dtFarmerFarmReports.Rows[j][
"nooffarms"
].ToString();
worksheet.Cells[(j1), 13].Value = dtFarmerFarmReports.Rows[j][
"produtionestimation"
].ToString();
worksheet.Cells[(j1), 14].Value = dtFarmerFarmReports.Rows[j][
"regionname"
].ToString();
worksheet.Cells[(j1), 15].Value = dtFarmerFarmReports.Rows[j][
"districtname"
].ToString();
worksheet.Cells[(j1), 16].Value = dtFarmerFarmReports.Rows[j][
"subdistrictname"
].ToString();
worksheet.Cells[(j1), 17].Value = dtFarmerFarmReports.Rows[j][
"villagename"
].ToString();
worksheet.Cells[(j1), 18].Value = dtFarmerFarmReports.Rows[j][
"sectionname"
].ToString();
worksheet.Cells[(j1), 19].Value = dtFarmerFarmReports.Rows[j][
"zonename"
].ToString();
worksheet.Cells[(j1), 20].Value = dtFarmerFarmReports.Rows[j][
"lastyearcooperative"
].ToString();
worksheet.Cells[(j1), 21].Value = dtFarmerFarmReports.Rows[j][
"currentyearcoop"
].ToString();
worksheet.Cells[(j1), 22].Value = dtFarmerFarmReports.Rows[j][
"farmer_details"
].ToString();
worksheet.Cells[(j1), 23].Value = dtFarmerFarmReports.Rows[j][
"farm_no"
].ToString();
worksheet.Cells[(j1), 24].Value = dtFarmerFarmReports.Rows[j][
"farm_visitno"
].ToString();
worksheet.Cells[(j1), 25].Value = dtFarmerFarmReports.Rows[j][
"farm_detailsdata"
].ToString();
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_one"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_one"
].ToString() ==
"-"
|| dtFarmerFarmReports.Rows[j][
"farm_picture_one"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 26].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 26].Value =
"Click to view"
;
worksheet.Cells[(j1), 26].Hyperlink =
new
Uri(dtFarmerFarmReports.Rows[j][
"farm_picture_one"
].ToString());
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_one_latitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_one_latitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 27].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 27].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_one_latitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_one_longitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_one_longitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 28].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 28].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_one_longitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_one_timestamp"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_one_timestamp"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 29].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 29].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_one_timestamp"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_two"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two"
].ToString() ==
"-"
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 30].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 30].Value =
"Click to view"
;
worksheet.Cells[(j1), 30].Hyperlink =
new
Uri(dtFarmerFarmReports.Rows[j][
"farm_picture_two"
].ToString());
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_two_latitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two_latitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 31].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 31].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_two_latitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_two_longitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two_longitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 32].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 32].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_two_longitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_two_timestamp"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two_timestamp"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 33].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 33].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_two_timestamp"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_three"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_two"
].ToString() ==
"-"
|| dtFarmerFarmReports.Rows[j][
"farm_picture_three"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 34].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 34].Value =
"Click to view"
;
worksheet.Cells[(j1), 34].Hyperlink =
new
Uri(dtFarmerFarmReports.Rows[j][
"farm_picture_three"
].ToString());
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_three_latitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_three_latitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 35].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 35].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_three_latitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_three_longitude"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_three_longitude"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 36].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 36].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_three_longitude"
].ToString();
}
if
(dtFarmerFarmReports.Rows[j][
"farm_picture_three_timestamp"
].ToString() ==
""
|| dtFarmerFarmReports.Rows[j][
"farm_picture_three_timestamp"
].ToString() ==
null
)
{
worksheet.Cells[(j1), 37].Value =
"-"
;
}
else
{
worksheet.Cells[(j1), 37].Value = dtFarmerFarmReports.Rows[j][
"farm_picture_three_timestamp"
].ToString();
}
worksheet.Cells[(j1), 38].Value = dtFarmerFarmReports.Rows[j][
"farm_areasqmeter"
].ToString();
worksheet.Cells[(j1), 39].Value = dtFarmerFarmReports.Rows[j][
"farm_areahectare"
].ToString();
worksheet.Cells[(j1), 40].Value = dtFarmerFarmReports.Rows[j][
"farm_declaredarea"
].ToString();
worksheet.Cells[(j1), 41].Value = dtFarmerFarmReports.Rows[j][
"farm_gpxarea"
].ToString();
worksheet.Cells[(j1), 42].Value = dtFarmerFarmReports.Rows[j][
"farm_area_bal"
].ToString();
worksheet.Cells[(j1), 43].Value = dtFarmerFarmReports.Rows[j][
"fieldstaffname"
].ToString();
var dict = JsonConvert.DeserializeObject<Dictionary<
string
,
string
>>(dtFarmerFarmReports.Rows[j][
"farm_detailsdata"
].ToString());
foreach
(var dicdata
in
dict)
{
int
colval = excelheaderlist.Where(x => x.colName == dicdata.Key).Select(y => y.colIndex).FirstOrDefault();
if
(colval > 0)
{ worksheet.Cells[(j1), colval].Value = dicdata.Value; }
}
}
worksheet.Cells[
"A2:BZ2"
].AutoFilter =
true
;
}
else
{
worksheet.Cells[
"A1:I1"
].Merge =
true
;
worksheet.Cells[
"A1:I1"
].Value =
"NO FARMER/FARM DATA"
;
worksheet.Row(1).Height = 35;
using
(var range = worksheet.Cells[1, 1, 1, 11])
{
range.Style.Font.Bold =
true
;
range.Style.Font.Size = 18;
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.Red);
range.Style.Font.Color.SetColor(Color.Black);
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
range.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
range.Style.ShrinkToFit =
false
;
}
}
worksheet.Cells.AutoFitColumns();
package.Workbook.Properties.Title =
"Farmer Reports"
;
package.Workbook.Properties.Author =
"Olam"
;
package.Workbook.Properties.Company =
"Olam"
;
package.Save();
modalPopupExport.Hide();
}
Response.Clear();
Response.ContentType = ContentType;
Response.AppendHeader(
"Content-Disposition"
,
"attachment; filename="
+ file.Name);
Response.WriteFile(outputDir + fileName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
}
catch
(Exception ex)
{
BindDetails();
this
.modalPopupExport.Hide();
showStatusTrue.Style.Add(
"display"
,
"none"
);
showStatusTrue.InnerHtml =
""
;
showStatusWarning.Style.Add(
"display"
,
"none"
);
showStatusWarning.InnerHtml =
""
;
showStatusAlready.Style.Add(
"display"
,
"none"
);
showStatusAlready.InnerHtml =
""
;
showStatusFalse.Style.Add(
"display"
,
"block"
);
showStatusFalse.InnerHtml =
"Something went wrong while export"
;
farmerid =
""
+ farmerid;
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"tmp"
,
"<script type='text/javascript'>myFunction();</script>"
,
false
);
Logger log =
new
Logger();
log.WriteToErrorLog(
"FARMER REPORTS EXCEL"
,
"EX"
, ex.Message.ToString(),
""
,
""
);
}
}
private
class
ExcelHeader
{
public
int
colIndex {
get
;
set
; }
public
string
colName {
get
;
set
; }
}
The above code working in Developement environment and build and publish the code in dev environment but in production environment shows error some thing went wrong while export.
how to solve this error. please let me know. I am trying to find out for last one day I cannot able to solve this error. please help me how to fix this error.
Reply
Answers (
5
)
Problem implementing Haar Cascade car
Get value from another form in already opened form1