Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am currently using .Net framework 3.5 and in that I am making use of
C#
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Office.Core;


By the help of code I am fetching xls sheet 'A' and making some modifications and saving it as 'B' in the same folder. Now, xls sheet 'A' is waste for me. How can I delete it ?
I tried using worksheet.delete() but it generated a exception saying file should be unhidden first etc etc. Can any of you please help me to achieve the same thing. ?
I will be highly thankful to you.
Posted

1 solution

Try this. I assumed that xls is in root folder. Change path according to your location.
Close the file if it is open.
C#
string path = Server.MapPath("MyTest.xls");
 FileInfo fi1 = new FileInfo(path);
if(fi1.Exists)
 fi1.Delete();
 
Share this answer
 
v3
Comments
Taresh Uppal 27-Aug-12 6:12am    
Thanx a zilion times ...:)
pradiprenushe 27-Aug-12 6:22am    
welcome

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