How to delete an Excel worksheet by using ASP.NET?

  • Thread starter Thread starter Guest
  • Start date Start date
Hi

You can use
File.Delete(@"c:\test.txt");
But ASP.NET Account should have write access to delete file.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

HTH
Ravikanth[MVP]
 
Any excel worksheet is simply a file, so

[VB]
System.IO.File.Delete("C:\Book1.xls")
[C#]
System.IO.File.Delete(@"C:\Book1.xls");

will do.

The account with which the worker process is running should have modify
rights on the file. Usually, the worker process runs under the
ASPNET_MachineName account or in Windows 2003 under NETWORK SERVICE account.
Alternativelly, impersonate a user that has modify rights on the file. See:

http://support.microsoft.com/?kbid=306158

Greetings
Martin
 
Hi, Shao Yong,

You need to open the workbook with com automation and remove the worksheet
using the Excel object model.

Hope this helps
Martin
Shao Yong said:
Sorry, i mean how to delete the sheet of an Excel document, not the file
itself.
 
Back
Top