I want to write some data to excelsheet file from datatable, i write this code
string path = "D:\\Project\\SMCCampaignmgmt\\trunk\\UserFolder\\NewFolder\\saran.xlsm";
oXL = new Microsoft.Office.Interop.Excel.Application();
oXL.Visible = false;
oXL.DisplayAlerts = false;
oXL.UserControl = false;
//error on this line
if (!File.Exists(path))
{
mWorkBook = oXL.Workbooks.Add();
}
else
{
mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
}
mWorkSheets = mWorkBook.Worksheets;
//Get the allready exists sheet
mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("Template");
Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
Missing.Value, Missing.Value, true, true, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
false,false, Missing.Value,
Missing.Value, Missing.Value);
mWorkBook.Close(Missing.Value, Missing.Value, Missing.Value);
mWSheet1 = null;
mWorkBook = null;
oXL.Quit();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
But am getting the error as Cannot access the file, because its readonly. How i can get rid.