0

I have developed a C# windows application. It reads data from an excel file and writes to a new excel work book. Created an EXE for this WinApp. If i run the application or EXE from the local machine, its working fine. Saving the new excel into my C drive. I copied the msi and exe files to another machine and installed the msi.

Following error is raising while running the exe from those machines. "Error in saving file".

Note:- No problem in reading the files. I checked it by browsing different type of files like .jpg, .doc, etc., In this scenario it asks us to browse the relevant file.

my code:

existingFileToWrite1 = @"C:\\LeadOwners-IN";
using (packageToWrite1 = new ExcelPackage(existingFileToWrite1))
{
 worksheetToWrite.Cells["A1"].Value = "Lead Owners Mail";
                                worksheetToWrite.Cells["B1"].Value = "TotalLeads-" + sRegion.Trim();
                                worksheetToWrite.Cells["C1"].Value = sLInfo + "1-" + sRegion.Trim();
                                worksheetToWrite.Cells["D1"].Value = sLInfo + "2-" + sRegion.Trim();
                                worksheetToWrite.Cells["E1"].Value = sLInfo + "3-" + sRegion.Trim();
                                worksheetToWrite.Cells["F1"].Value = sLInfo + "4-" + sRegion.Trim();
                                worksheetToWrite.Cells["G1"].Value = sLInfo + "5-" + sRegion.Trim();
                                worksheetToWrite.Cells["H1"].Value = sLInfo + "6-" + sRegion.Trim();
                                worksheetToWrite.Cells["I1"].Value = sLInfo + "7-" + sRegion.Trim();
                                worksheetToWrite.Cells["J1"].Value = sLInfo + "8-" + sRegion.Trim();
                                worksheetToWrite.Cells["K1"].Value = sLInfo + "9-" + sRegion.Trim();
                                worksheetToWrite.Cells["L1"].Value = sLInfo + "10-" + sRegion.Trim();

worksheetToWrite.Cells["C" + Iteration1].Value = sFull1.Substring(0, sFull1.Length);
                                    worksheetToWrite.Cells["D" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["E" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["F" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["G" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["H" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["I" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["J" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["K" + Iteration1].Value = string.Empty;
                                    worksheetToWrite.Cells["L" + Iteration1].Value = string.Empty;

packageToWrite1.Save();
}

Please advice me on this to get the solution. Thanks in advance.

Venil
  • 83
  • 2
  • 4
  • 9
  • I think you need to close the doc after save.....and use try,catch,finally block for proper error handling. – jiten Oct 18 '13 at 07:45
  • Does your user has write privileges on the machine? – user1567896 Oct 18 '13 at 08:21
  • @TheProvost: in ExcelPackage(existingFileToWrite1), "existingFileToWrite1" is a parameter. Value for that is given in the above line. (existingFileToWrite1 = @"C:\\LeadOwners-IN";) – Venil Oct 18 '13 at 09:54
  • @user1567896: Don't have those privileges in my machine. – Venil Oct 18 '13 at 09:57

1 Answers1

0

"Don't have those privileges in my machine."

There you go. Probably a security issue since you dont have the right privileges for the "C:\" directory...

hmm try running visual studio as administator...right click on visual studio then choose run as administrator and see if that works

TheProvost
  • 1,832
  • 2
  • 16
  • 41