Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using the following c# code to save an excel file in the application start-up path folder. But it's saving in 'My Documents' Folder. Can someone please explain?
Thank you

string dailyFile = "DeliveryChallan(" + date + time + ").xls";

File.Copy(Application.StartupPath + "\\DCTemplate.xls", 
    Application.StartupPath + dailyFile);

Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = App.Workbooks.Open(Application.StartupPath + dailyFile,
    misValue, misValue, misValue, misValue, misValue, 
    misValue, misValue, misValue, misValue, misValue, 
    misValue, misValue, misValue, misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

xlWorkBook.Save();
xlApp.Workbooks.Close();
xlApp.Quit();
Posted
Updated 9-Nov-10 0:26am
v2

1 solution

Insufficient rights? If it is Vista or later, try running as admin.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900