We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Asp.net web forms Gantt implement Pdf Export feature getting error

Thread ID:

Created:

Updated:

Platform:

Replies:

130608 May 20,2017 04:17 PM UTC May 31,2017 07:13 AM UTC ASP.NET Web Forms 9
loading
Tags: Gantt
Sam
Asked On May 20, 2017 04:17 PM UTC

Hello,

Please help on error Gantt export features.

protected void Gantt1_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GanttEventArgs e)
        {
            // gantt export pdf

            PdfExport exp = new PdfExport();
            GanttPdfExportSettings settings = new GanttPdfExportSettings();
            settings.EnableFooter = false;
            settings.ProjectName = "Project Promantas";
            settings.Locale = e.Arguments["locale"].ToString();
            settings.Theme = GanttExportTheme.FlatLime;
            exp.Export(this.Gantt1.Model, (IEnumerable)Gantt1.DataSource, settings, "GanttReport");
        }

I get error exception from line highlight above

System.ArgumentOutOfRangeException occurred
  HResult=0x80131502
  Message=The added or subtracted value results in an un-representable DateTime.
  Source=mscorlib
  StackTrace:
   at System.DateTime.AddTicks(Int64 value)
   at System.DateTime.Add(Double value, Int32 scale)
   at System.DateTime.AddDays(Double value)
   at Syncfusion.EJ.Export.GanttPdfExport.ProcessScheduleHeader()
   at Syncfusion.EJ.Export.GanttPdfExport.ExecuteResult(GanttProperties ganttModel, IEnumerable dataSource)
   at Syncfusion.EJ.Export.GanttPdfExport.Export(GanttProperties treeGridProperties, IEnumerable dataSource, Boolean exportToFile)
   at Syncfusion.EJ.Export.PdfExport.Export(GanttProperties ganttModel, IEnumerable datasource, GanttPdfExportSettings settings, String fileName)
   at ProjectManagementTool.ActGantt.Gantt1_ServerPdfExporting(Object sender, GanttEventArgs e) in C:\Users\samtn\Documents\Visual Studio 2017\Projects\Promantas\ProjectManagementTool\ProjectManagementTool\ActGantt.aspx.cs:line 1405
   at Syncfusion.JavaScript.Web.Gantt.PostBackEventHandler(String EventName, Dictionary`2 args)
   at Syncfusion.JavaScript.Web.CommonDataBoundControl.RaisePostBackEvent(String EventArgument)

Thank you.

Jayakumar Duraisamy [Syncfusion]
Replied On May 22, 2017 10:52 AM UTC

Hi Sam, 
We regret for the inconvenience caused. 
We have analyzed your code snippet with our sample but the reported issue was not reproduced. From the call stack information, we are suspecting that there might be invalid date format were used for scheduleStartDate and scheduleEndDate. We have prepared a sample with PDF export option, please find the sample location as below. 
If you still facing this issue, please revert us by modifying the sample based on your application with following information, this will be helpful to serve you better. 
  1. Value of Locale and DateFormat used in your sample.
  2. Value of ScheduleStartDate and ScheduleEndDate.
  3. Your system locale information.
Regards, 
Jayakumar D 


Sam
Replied On May 22, 2017 08:53 PM UTC

Thanks for your response. I did try your sample and it works great.  I modified my code to make DateFormat="M/d/yyyy". Now, I got different error on the same line.
My project had a few custom columns and they were been re-ordered during Gantt's load function (javascript).  Does this effect of this exporting feature?

Error is:
System.IndexOutOfRangeException occurred
  HResult=0x80131508
  Message=Index was outside the bounds of the array.
  Source=Syncfusion.EJ.Export
  StackTrace:
   at Syncfusion.EJ.Export.GanttPdfExport.InitializePdf(PdfDocument pdfDocument)
   at Syncfusion.EJ.Export.GanttPdfExport.ExecuteResult(GanttProperties ganttModel, IEnumerable dataSource)
   at Syncfusion.EJ.Export.GanttPdfExport.Export(GanttProperties treeGridProperties, IEnumerable dataSource, Boolean exportToFile)
   at ProjectManagementTool.ActGantt.Gantt1_ServerPdfExporting(Object sender, GanttEventArgs e) in C:\Users\it014527\Documents\Visual Studio 2015\Projects\Promantas\ProjectManagementTool\ProjectManagementTool\ActGantt.aspx.cs:line 1406
   at Syncfusion.JavaScript.Web.Gantt.PostBackEventHandler(String EventName, Dictionary`2 args)
   at Syncfusion.JavaScript.Web.CommonDataBoundControl.RaisePostBackEvent(String EventArgument)


1. Value of Locale and DateFormat used in your sample.     
value of Locale is exact with your sample. DateFormat was fixed using "M/d/yyyy"
2. Value of ScheduleStartDate and ScheduleEndDate.
we don't use ScheduleStartDate and ScheduleEndDate; we used "StartDate" and "EndDate"
3. Your system locale information.
it is  same locale with  your sample

Thank you for you help.


Jayakumar Duraisamy [Syncfusion]
Replied On May 23, 2017 11:30 AM UTC

Hi Sam, 
We have checked Gantt PDF export support with custom columns but we can’t reproduce the reported issue, we have prepared a sample with custom columns and PDF export option. 
Please find the sample location as below. 
Make sure that the Gantt columns are rendering properly based on its visible property and value of TreeColumnIndex property. If you still facing this issue please revert us by modifying the sample with detailed information and code snippet, this would be helpful for us to serve you better. 
Regards, 
Jayakumar D 


Sam
Replied On May 23, 2017 05:55 PM UTC

Hello,

Finally, I found where root caused the error. I took your sample and made a few modification (I will be posted code below).  Because our project required a dropdown field in a custom column, so I manually created and populated its data on Gantt load function.  Then I tried the export PDF/Excel, it gave me errors below accordingly PDF or Excel exports.

PDF export:

System.ArgumentOutOfRangeException: 'The added or subtracted value results in an un-representable DateTime.'

Excel export:

System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values.'


ASPX:

<asp:Content ID="content" runat="server" ContentPlaceHolderID="MainContent">
 
    <script src='<%=Page.ResolveClientUrl("~/Scripts/Gantt/TaskInfo.js"%>'></script>
 
    <ej:Gantt runat="server" ID="GanttControlExporting" ChildMapping="Children" 
        TreeColumnIndex="1" IsResponsive="true"
        ParentTaskIdMapping="ParentId"
        TaskIdMapping="TaskId"
        TaskNameMapping="TaskName"
        StartDateMapping="StartDate"
        EndDateMapping="EndDate"
        DurationUnit="Day"
        DateFormat="M/d/yyyy"
        DurationMapping="Duration"
        ProgressMapping="Progress"
        ResourceIdMapping="ResourceId"
        ResourceNameMapping="ResourceName" 
        PredecessorMapping="Predecessor"
        ShowProgressStatus="true"
        ShowColumnChooser="true"
        SplitterPosition="95%"
        AllowGanttChartEditing="false"
        EnableContextMenu="true"
        AllowColumnResize="true"
        AllowSorting="false" 
        AllowMultiSorting="true"
        IncludeWeekend="false" HighlightWeekends="true"
        EnableWBS="true"
        EnableWBSPredecessor="false"
        Load="load"
        OnServerPdfExporting="GanttControlExporting_ServerPdfExporting" OnServerExcelExporting="GanttControlExporting_ServerExcelExporting">
        <EditSettings AllowDeleting="true" AllowEditing="true" AllowAdding="true" AllowIndent="true"
            EditMode="cellEditing" />
        <SizeSettings Width="100%" Height="450px" />
        <ToolbarSettings ShowToolbar="true" 
            ToolbarItems="add,edit,delete,update,cancel,indent,outdent,expandAll,collapseAll,pdfExport,excelExport" />
    </ej:Gantt>
    <script type="text/x-jsrender" id="investigateColumnTemplate1">
            <div style="margin-left20px;">
                {{if Investigate}}
                    <input class="customCheckbox" type="checkbox" disabled="disabled" checked="checked" value="" />{{else}}
                    <input class="customCheckbox" type="checkbox" disabled="disabled" value="" />{{/if}}
            </div>
        </script>
        <script type="text/x-jsrender" id="WbsColumnTemplate">
            <div>
                {{:~WBS}}            
            </div>
        </script>
    <script type="text/javascript">
        function load(args) {
            var columns = this.getColumns();
            var col1 = {
                field: "ResourceName",
                headerText: "Resource",
                editType: "stringedit",
                mappingName: "ResourceName"
            },
                col2 = {
                    field: "TeamName",
                    headerText: "Team",
                    mappingName: "TeamName",
                    editType: "dropdownedit",
                    dropdownData: null,
                    editParams: { fields: { text: "TeamName", value: "TeamName" }, showCheckbox: false },
                    width: "80px"
                },
                col3 = {
                    field: "ParentId",
                    headerText: "Parent",                    
                    mappingName: "ParentId",
                    editType: "numericedit",
                    width: "57px"
                },
                investCol = {
                    field: "Investigate",
                    headerText: "Investigate",
                    mappingName: "Investigate",
                    editType: "booleanedit",
                    isTemplateColumn: true,
                    templateID: "investigateColumnTemplate1",
                    width: "55px"
                },
                wbsCol = {
                    field: "WBS",
                    headerText: "WBS",
                    width: 75,
                    allowEditing: false,
                    mappingName: "WBS"
                };
 
            columns.splice(2, 0, col1);
            columns.splice(4, 0, col2);
            columns.splice(6, 0, col3);
            columns.splice(7, 0, investCol);
            columns.splice(11, 1);
            columns.splice(11, 0, wbsCol);
             TaskInfo.getTeams(function (result) {
                columns[4].dropdownData = result; //JSON retur
            });
        }
    </script>
</asp:Content>

.CS Code behind

protected void Page_Load(object sender, EventArgs e)
{
    // var DataSource = this.GetDataSource();
    var DataSource = GetTaskSource();
    this.GanttControlExporting.DataSource = DataSource;
    this.GanttControlExporting.DataBind();
}
private List<TaskData> GetTaskSource() {
// get task from database here
}
protected void GanttControlExporting_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GanttEventArgs e)
{
    PdfExport exp = new PdfExport();
    GanttPdfExportSettings settings = new GanttPdfExportSettings();
    settings.IncludeTemplateColumn = true;
    settings.EnableFooter = true;
    settings.ProjectName = "Project Tracker";
    settings.Locale = e.Arguments["locale"].ToString();
    settings.Theme = GanttExportTheme.FlatLime;
    exp.Export(this.GanttControlExporting.Model, (IEnumerable)this.GanttControlExporting.DataSource, settings, "Gantt");
}
 
protected void GanttControlExporting_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GanttEventArgs e)
{
    ExcelExport exp = new ExcelExport();
    GanttExportSettings settings = new GanttExportSettings();
    settings.Theme = ExportTheme.FlatLime;
    exp.Export(this.GanttControlExporting.Model, (IEnumerable)this.GanttControlExporting.DataSource, 
        "Export.xlsx"ExcelVersion.Excel2010, new GanttExportSettings() { Theme = ExportTheme.FlatLime });
}
public class TaskData
    {
        public int ProjectId { getset; }
        public string StartDate { getset; }
        public string EndDate { getset; }
        public int TaskId { getset; }
        public int ParentId { getset; }
        public string TaskName { getset; }
public int Duration { getset; }
       public int Progress { getset; }
       public int PercentDone { getset; }
public string Predecessor { getset; }
       public string WBS { getset; }
public string ResourceName { get; set; }
public string TeamId { get; set; }
public string TeamName { get; set; }
public bool Investigate {get; set;}
}


Jayakumar Duraisamy [Syncfusion]
Replied On May 24, 2017 12:58 PM UTC

Hi Sam, 
Thanks for shared sample code. 
We have run your provided code snippet with our data source but we couldn’t able to reproduce the reported issue. 
In PDF export reported error may cause due to date time calculation, so we need data source to find the exact root cause of this issue. 
And we have analyzed your code snippet, we had following clarification. 
  1. You have used custom column to show resource in Gantt control and assigned value to following properties “ResourceIdMapping”,”ResourceNameMapping”. Gantt control has inbuilt support to map the resource to the tasks. Please refer the following link for more information about resource
And also we can use custom column to show resource names, for this we no need to provide the value to resource support related properties. 
  1. You have added custom column to show WBS value of task in Gantt. Have you mapped WBS value of task from data source? If yes, we no need to enable WBS support in with “EnableWBS” property. It may conflict the default WBS column in Gantt.
We have prepared a sample with your code snippet with our data source, can you modify this data similar to your sample data source, it may helpful to find the root cause of this issue. 
Please find the sample location below. 
Regards, 
Jayakumar D 


Sam
Replied On May 24, 2017 08:10 PM UTC

Hello,

Please see my attachment and I included a local Gantt.mdf (v.13.00.1601) under AppData of Project Solution.

Please try the attached project to see if you get same error? And Can you help me how to populate dropdown data when inline edit (double click) Team column.

I also put comments on Default.aspx page.

// Get Teams Data for the DropDown from TaskInfo.js script
            TaskInfo.getTeams(function (result) {
                columns[4].dropdownData = result; // this cause ERROR: ArgumentOutOfRangeException: 'The added or subtracted value results in an un-representable DateTime.'
                //teams = result; // This works, but NO VALUES in dropdown
                console.log(result);
            });

Thank you for your help.




Attachment: Sample_5ced27a9.zip

Jayakumar Duraisamy [Syncfusion]
Replied On May 25, 2017 03:50 PM UTC

Hi Sam, 
Thanks for the sample. 
We have analyzed the entire code flow of given sample and we can able to reproduce the reported issue. 
The root cause of this due to returning list of team from web service and the list contains invalid property, due to this parsing error occurred at server. Hence it collapsed the Gantt column collection value. 
To resolve this problem, we have to return list as serialized data from the web service and this serialized data is converted to JSON object at the Ajax success method to get the valid dropdown data. 
 
As we are getting dropdown data using Ajax request, hence columns were rendered before getting dropdown data due to ajax asynchronous execution.  
So, we need to use “async” as false in the ajax property to overcome the dropdown data population issue. 
Please refer following code snippet, 
[TaskInfo.asmx.cs] 
public object GetTeams() 
        { 
//… 
     var jsonSerialiser = new JavaScriptSerializer(); 
     var teamData = jsonSerialiser.Serialize(teamDataCollection); 
     return teamData; 
} 
[TaskInfo.js] 
var getTeams = function (callback) { 
      
        // get Teams 
        $.ajax({ 
            type: 'GET', 
            async: false, 
//… 
          success: function (result) {                
                callback(JSON.parse(result.d)); 
            }, 
We have modified your sample and you can perform PDF & Excel Export without any issues. Please find the sample location as below, 
Please let us know if you require further assistance on this. 
Regards, 
Jayakumar D 


Sam
Replied On May 30, 2017 12:56 PM UTC

Thank you very much! It works.

Your supports are awesome.

Jayakumar Duraisamy [Syncfusion]
Replied On May 31, 2017 07:13 AM UTC

Hi Sam, 
We are glad that your issue has been resolved. Please let us know if you need any other assistance. 
Regards, 
Jayakumar D 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;