timberadmin
asked on
C# console app to save csv file
Hi experts,
I've made a console app that basically does this:
1. Open .xlsx file
2. save the worksheet called "Load" as a xlCSV using Office.Interop.Excel. Code also attached.
// Get fully qualified path for xlsx file
var spreadsheetLocation = Path.Combine(@"E:\SGGG\LBD ", "LastBusinessDay.xlsx");
var exApp = new Application();
exApp.Visible = false;
exApp.DisplayAlerts = false;
var exWbk = exApp.Workbooks.Open(sprea dsheetLoca tion);
var exWks = (Microsoft.Office.Interop. Excel.Work sheet)exWb k.Sheets[" Load"];
exWks.SaveAs(@"E:\SGGG\LBD .csv", XlFileFormat.xlCSV);
exWbk.Close();
The code all works fine if i just run the .exe file manually. However, I need to schedule this so that it runs once a day by Windows Task Scheduler and this is where it runs into problems.
I've told the task to run whether user is logged on or not and run with the highest privileges. Action is pointed to the .exe file of my console app. Again, if i run it outside of scheduler, it works as expected. When I run it in scheduler, it tells me successful but no csv is saved and Excel hangs in the background (i have to end task in task manager)...
Supremely weird. Please help
I've made a console app that basically does this:
1. Open .xlsx file
2. save the worksheet called "Load" as a xlCSV using Office.Interop.Excel. Code also attached.
// Get fully qualified path for xlsx file
var spreadsheetLocation = Path.Combine(@"E:\SGGG\LBD
var exApp = new Application();
exApp.Visible = false;
exApp.DisplayAlerts = false;
var exWbk = exApp.Workbooks.Open(sprea
var exWks = (Microsoft.Office.Interop.
exWks.SaveAs(@"E:\SGGG\LBD
exWbk.Close();
The code all works fine if i just run the .exe file manually. However, I need to schedule this so that it runs once a day by Windows Task Scheduler and this is where it runs into problems.
I've told the task to run whether user is logged on or not and run with the highest privileges. Action is pointed to the .exe file of my console app. Again, if i run it outside of scheduler, it works as expected. When I run it in scheduler, it tells me successful but no csv is saved and Excel hangs in the background (i have to end task in task manager)...
Supremely weird. Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
double click to open properties and set it "Run whether user is logged on or not" + "Highest Privilages"
Screenshot---2017-06-19---5_11_32-PM.png