Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using Excel Interop to read excel files which are attached in library items. It's working fine in development environment however it throws following error when deployed in production server,

enter image description here

When I review the code step by step found there is no problem in reading excel sheet but it's happening when updating list item,

Here is my code,

foreach (ListItem listItem in listItems)
                    {
                        if (listItem["ImportStatus"] != null)
                        {
                            if (listItem["ImportStatus"].ToString() == "Pending")
                            {
                                string strJobNumber = string.Empty;
                                string strCrew = string.Empty;
                                int RDSDocID=0;
                                DateTime dtRDSDate = DateTime.Now;

                                string excelname = listItem["FileLeafRef"].ToString();

                                if (!string.IsNullOrEmpty(excelname))
                                {
                                    string workbookPath = _context + "/NAMRDS/" + excelname;

                                    rtLog.Text += "Processing item ID : " + listItem["ID"].ToString() + " - " + " Reading file : " + excelname + "...\n";

                                    excel = new ApplicationClass();
                                    excel.Visible = false;

                                    excelWorkbook = excel.Workbooks.Open(workbookPath, 0, true, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);

                                    Sheets sheets = excelWorkbook.Worksheets;
                                    Worksheet worksheet = (Worksheet)sheets.get_Item("Downtime");

                                    if ( worksheet != null )
                                    {
                                        rtLog.Text += "Creatig items in TimeUsage list for file : " + excelname + "...\n";

                                        if (listItem["JobNumber"] != null) { strJobNumber = listItem["JobNumber"].ToString(); }
                                        if (listItem["Crew"] != null) { strCrew = listItem["Crew"].ToString(); }
                                        if (listItem["ID"] != null) { RDSDocID = Convert.ToInt32(listItem["ID"].ToString()); }
                                        if (listItem["RDSDate"] != null) { dtRDSDate = Convert.ToDateTime(listItem["RDSDate"].ToString()); }

                                        for (int i = 6; i <= 200; i++)
                                        {

                                            double d_ns = 0;
                                            double d_ds = 0;

                                            if (worksheet.get_Range("G" + i).get_Value() != null || worksheet.get_Range("I" + i).get_Value() != null)
                                            {
                                                string c = string.Empty;
                                                string d = string.Empty;

                                                if (worksheet.get_Range("G" + i).get_Value() == null)
                                                {
                                                    c = string.Empty;
                                                }
                                                else
                                                {
                                                    c = worksheet.get_Range("G" + i).get_Value().ToString();
                                                }
                                                if (worksheet.get_Range("I" + i).get_Value() == null)
                                                {
                                                    d = string.Empty;
                                                }
                                                else
                                                {
                                                    d = worksheet.get_Range("I" + i).get_Value().ToString();
                                                }

                                                if (worksheet.get_Range("M" + i).get_Value() != null)
                                                {
                                                    d_ns = Convert.ToDouble(worksheet.get_Range("M" + i).get_Value().ToString());
                                                }

                                                if (worksheet.get_Range("N" + i).get_Value() != null)
                                                {
                                                    d_ds = Convert.ToDouble(worksheet.get_Range("N" + i).get_Value().ToString());
                                                }

                                                if (d_ns > 0 || d_ds > 0)
                                                {
                                                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                                                    ListItem lItem = listDowntime.AddItem(itemCreateInfo);

                                                    lItem["Category"] = c;
                                                    lItem["Details"] = d;
                                                    lItem["Total"] = d_ns + d_ds;

                                                    lItem["JobNumber"] = strJobNumber;
                                                    lItem["Crew"] = strCrew;
                                                    lItem["RDSReference"] = RDSDocID;
                                                    lItem["RDSDate"] = dtRDSDate;

                                                    lItem.Update();
                                                }
                                            }
                                        }

                                        listItem["ImportedDateTime"] = DateTime.Now;
                                        listItem["ImportStatus"] = "Imported";

                                        rtLog.Text += "Before re-saving NAMRDS item";

                                        listItem.Update();

                                        _clientcontext.ExecuteQuery();

                                        iFileCount += 1;

                                    }
                                    else
                                    {
                                        rtLog.Text += "Processing item ID : " + listItem["ID"].ToString() + " 'DownTime' sheet not found...\n";
                                    }
                                }
                                else
                                {
                                    rtLog.Text += "Processing item ID : " + listItem["ID"].ToString() + " attachment not found...\n";
                                }
                            }
                        }
                    }

I get the message "Before re-saving NAMRDS item" but after that error throws possibly at following line,

 listItem.Update();
    _clientcontext.ExecuteQuery();

I've "List View Lookup Threshold" setting is 20 at the server.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.