this error appears if you have tried to save a workbook on a drive and you do not have Modify and Delete permissions to the location where the file is being saved. It is also possible that another user has a read lock on the file.
Excel saves a file using three steps (if the file already exists in the target location):
Creates a temporary file with a randomly generated name, such as 4CCA4100.
Deletes the original file.
Renames the temporary file to the original file name.
If Excel cannot delete the original file or cannot rename the temporary file, this error message appears.
To temporarily work around this problem (providing another user does not have a read lock on the file), save the workbook to a local hard disk, or to a folder where you do have Modify and Delete rights. You may then be able to copy the file to the network drive.
This problem can also appear if you have an antivirus program installed either on your computer or on the network server. If this is the case, you may want to temporarily turn off or remove the antivirus program. If Microsoft Office Excel begins to save files correctly, contact the anti-virus vendor and ask if there is an update or correction to this problem.
More information about this error message online.
![]() |
0 |
![]() |
Can we see your code? I got this sort of error before after saving a PDF file to disk. For me, it was an error in my code.
"If you have knowledge, let others light their candles in it."
— Margaret Fuller
![]() |
0 |
![]() |
public static void ExportMediaPlan(string fileName, DataSet dsMediaPlan, int custId, string typeOfFile) { #region Member List<string> List = null; Application oXL = null ; Workbook oWB = null ; Worksheet oSheetSecond = null ; Worksheet oSheet = null ; Range oRng= null ; Range xlsRange = null ; Range xlRangecell = null ; object oMissing = System.Reflection.Missing.Value; #endregion Member try { #region Initialization......... GC.Collect();// clean up any other excel guys hangin' around... oXL = new Application(); oXL.Visible = false; oXL.DisplayAlerts = false; oWB = (Workbook)(oXL.Workbooks.Add(true)); oSheet = (Worksheet)oWB.Worksheets[1]; oSheet.Name = "Media Plan"; oSheetSecond = (Worksheet)oWB.Worksheets.Add(Type.Missing, oSheet, 1, Type.Missing); oSheetSecond.Name = "Lists"; oSheet.Activate(); #endregion Initialization......... #region Header Creation For Sheet Name Media Plan and Entire Creation of Sheet Name Lists ............. int i = 1; for (int j = 0; j < dsMediaPlan.Tables[0].Columns.Count; j++) { oSheet.Cells[1, j + 1] = dsMediaPlan.Tables[0].Columns[j].ColumnName; if (Enum.IsDefined(typeof(Enumeration.FieldName), dsMediaPlan.Tables[0].Columns[j].ColumnName)) { oSheetSecond.Cells[1, i] = dsMediaPlan.Tables[0].Columns[j].ColumnName; List = Enumeration.GetDropDownList(dsMediaPlan.Tables[0].Columns[j].ColumnName, custId); int iRowNew = 2; for (int data = 0; data < List.Count; data++) { oSheetSecond.Cells[iRowNew, i] = List[data].ToString(); iRowNew++; } string s1 = ColumnLetter(i) + "2"; oSheetSecond.get_Range(s1, ColumnLetter(i) + (List.Count + 1)).Name = dsMediaPlan.Tables[0].Columns[j].ColumnName; i++; List.Clear(); } } #endregion Header Creation For Sheet Name Media Plan............. #region Data Display in Sheet Name Media Plan..................... int rowLimit; rowLimit = (typeOfFile == Enumeration.TypeOfFile.template.ToString()) ? 50 : dsMediaPlan.Tables[0].Rows.Count; int iRow = 2; for (int iR = 0; iR < rowLimit; iR++) { int cellNum = 0; foreach (DataColumn dc in dsMediaPlan.Tables[0].Columns) { string s1 = string.Empty; string formula = string.Empty; bool formulaCheck = Enum.IsDefined(typeof(Enumeration.FieldName), dc.ColumnName.ToString()); if (formulaCheck) { s1 = ColumnLetter(dc.Ordinal + 1) + iRow; formula = "=" + dc.ColumnName.ToString(); xlsRange = oSheet.get_Range(s1, s1); xlsRange.Validation.Add(XlDVType.xlValidateList, XlDVAlertStyle.xlValidAlertStop, System.Type.Missing, formula, System.Type.Missing); xlsRange.Validation.ShowError = false; if (typeOfFile != Enumeration.TypeOfFile.template.ToString()) { xlsRange.Formula = dsMediaPlan.Tables[0].Rows[iR][dc].ToString().Replace("''", "'"); xlsRange.Interior.Color = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.LightBlue); } } else { if (typeOfFile != Enumeration.TypeOfFile.template.ToString()) { oSheet.Cells[iRow, cellNum + 1] = dsMediaPlan.Tables[0].Rows[iR][dc].ToString().Replace("''", "'"); xlRangecell = (Range)oSheet.Cells[iRow, cellNum + 1]; xlRangecell.Interior.Color = System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.LightBlue); } } cellNum++; } iRow++; } #endregion Data Display in Sheet Name Media Plan..................... #region Format First Row of Both Sheets.................. //Format A1:Z1 as bold, vertical alignment = center. oSheetSecond.get_Range("A1", "IV1").Font.Bold = true; oSheetSecond.get_Range("A1", "IV1").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; //AutoFit columns A:Z. oRng = oSheetSecond.get_Range("A1", "IV1"); oRng.EntireColumn.AutoFit(); //Format A1:Z1 as bold, vertical alignment = center. oSheet.get_Range("A1", "IV1").Font.Bold = true; oSheet.get_Range("A1", "IV1").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; //AutoFit columns A:Z. oRng = oSheet.get_Range("A1", "IV1"); oRng.EntireColumn.AutoFit(); oXL.Visible = false; oXL.UserControl = false; #endregion Format First Row of Both Sheets.................. #region Display Excel File.................... System.IO.Directory.GetAccessControl(fileName, System.Security.AccessControl.AccessControlSections.Access); System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.IsReadOnly = false; oWB.SaveAs(fileName, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); #endregion Display Excel File.................... dsMediaPlan.Dispose(); dsMediaPlan = null; oWB.Close(true, fileName, Type.Missing); } catch (Exception theException) { throw theException; } finally { #region CleanUp all Objects...................... oXL.Workbooks.Close(); oXL.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(oRng); System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL); oXL = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet); oSheet = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB); oWB = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheetSecond); oSheetSecond = null; GC.Collect(); // force final cleanup! #endregion CleanUp all Objects...................... } }
![]() |
0 |
![]() |