Quocatentomma
New Member
I am facing a very strange problem in adding a picture to my excel sheet.I am using \[code\]wrkshit.Shapes.AddPicture(pathNew, Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoCTrue, 56, 52, 800, 550);\[/code\]to add a picture to my excel. When i run it locally on my PC, the excel is generated with pictures embedded in it. But when I run it on server, It hangs on this particular line of code and throws no exception.Can any body suggest me a way out. Please..Here is my complete code...\[code\] string buildURL = " http://maps.googleapis.com/maps/api/staticmap?center=" + bounds.getCenter() + "&zoom=" + (GMap1.GZoom + 3).ToString() + "&size=800x550&maptype=roadmap"; for (int t = 0; t < result2.Count; t++) { result2[t].sno = (t + 1).ToString(); buildURL = buildURL + "&markers=color:red|label:" + (t + 1).ToString() + "|" + result2[t].lat.ToString() + "," + result2[t].lng.ToString(); } buildURL = buildURL + "&sensor=false"; string pathNew = null; using (WebClient wc = new WebClient()) { DateTime currentTime = DateTime.UtcNow.Add(new TimeSpan(int.Parse(Session["Hours"].ToString()), int.Parse(Session["Minutes"].ToString()), 0)); //pathNew = @"D:\GoogleImages\" + (txtMobile.Items[k].Text).Trim().Replace(" ", "_") + "_" + currentTime.ToString("yyyyMMdd") + ".png"; pathNew = Server.MapPath("~/StoppageReport") +"\\"+ (txtMobile.Items[k].Text).Trim().Replace(" ", "_") + "_" + currentTime.ToString("yyyyMMdd") + ".png"; if (File.Exists(pathNew)) { File.Delete(pathNew); } wc.UseDefaultCredentials = true; wc.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); wc.DownloadFile(buildURL, pathNew); } wrkshit = ((Worksheet)wrkbuk.Worksheets[k + 1]); string name = txtMobile.Items[k].Text.Replace(" ", "_").Replace(".", "_").Replace("[", "_").Replace("]", "_"); wrkshit.Name = name; //wrkshit.Name = (result2.Count - k).ToString(); wrkshit.Shapes.AddPicture(pathNew, Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoCTrue, 56, 52, 800, 550); wrkshit.Cells[20, 15] = txtMobile.Items[k].Text; wrkshit.Cells[21, 15] = txt_fordate.Text; for (int p = 0; p < result2.Count; p++) { wrkshit.Cells[25 + p, 1] = (p + 1).ToString(); wrkshit.Cells[25 + p, 2] = result2[p].address; wrkshit.Cells[25 + p, 8] = (result2[p].startTime).ToString(); wrkshit.Cells[25 + p, 12] = result2[p].endTime.ToString(); wrkshit.Cells[25 + p, 16] = (result2[p].duration).ToString(); } } else { wrkshit = ((Worksheet)wrkbuk.Worksheets[k + 1]); string name = txtMobile.Items[k].Text.Replace(" ", "_").Replace(".", "_").Replace("[", "_").Replace("]", "_"); wrkshit.Name = name; //wrkshit.Name = (result2.Count - k).ToString(); wrkshit.Cells[20, 15] = txtMobile.Items[k].Text; wrkshit.Cells[21, 15] = txt_fordate.Text; wrkshit.Cells[25, 1] = "N/A"; wrkshit.Cells[25, 2] = "N/A"; wrkshit.Cells[25, 8] = "N/A"; wrkshit.Cells[25, 12] = "N/A"; wrkshit.Cells[25, 16] = "N/A"; } } else { wrkshit = ((Worksheet)wrkbuk.Worksheets[k + 1]); string name = txtMobile.Items[k].Text.Replace(" ", "_").Replace(".", "_").Replace("[", "_").Replace("]", "_"); wrkshit.Name = name; //wrkshit.Name = (result2.Count - k).ToString(); wrkshit.Cells[20, 15] = txtMobile.Items[k].Text; wrkshit.Cells[21, 16] = txt_fordate.Text; wrkshit.Cells[25, 1] = "N/A"; wrkshit.Cells[25, 2] = "N/A"; wrkshit.Cells[25, 8] = "N/A"; wrkshit.Cells[25, 12] = "N/A"; wrkshit.Cells[25, 16] = "N/A"; } //else //{ // if (result.resultStatus == heuroFileReader.resultStatus.PHONE_WAS_NOT_ON) // { // err("Phone was not On or the required XML config file was not recieved"); // } // else // { // err(result.resultStatus.ToString()); // } // } #endregion #region Delete Worksheets for (int p = wrkbuk.Worksheets.Count; p >k; p--) { app.DisplayAlerts = false; Worksheet worksheet = (Worksheet)wrkbuk.Worksheets[p]; worksheet.Delete(); app.DisplayAlerts = true; } #endregion #region Save Excel wrkbuk.DoNotPromptForConvert = true; if (File.Exists(Server.MapPath("~/StoppageReport/" + Session["accountID"].ToString() + "_" + txt_fordate.Text.Replace("/", "_") + ".xlsx"))) { File.Delete(Server.MapPath("~/StoppageReport/" + Session["accountID"].ToString() + "_" + txt_fordate.Text.Replace("/", "_") + ".xlsx")); } wrkbuk.SaveAs(Server.MapPath("~/StoppageReport/" + Session["accountID"].ToString() + "_" + txt_fordate.Text.Replace("/", "_") + ".xlsx"), misval, misval, misval, misval, misval, XlSaveAsAccessMode.xlExclusive, misval, misval, misval, misval, misval); wrkbuk.Close(null, null, null);\[/code\]