Delete a file from folder

Hi Champs,

It would be a great help. If someone could guide me. I am creating a temp xlsx file to do some manipulation but after doing manipulation i have to delete the file . How can i delete the file by the name . i dont want to provide folder path as the file would be in the project folder . All i want is to delete the file by its name.

Thanks !!

Hi @Shikhar_Tandon, Are you creating a file or downloading a file? If creating a new file, you cannot create a temp.xlsx without specifying the location of the file? (Correct me if not)

use delete activity, after making sure it is released by the process.

@Shikhar_Tandon Delete Activity actually worked without giving the location of the file if it is stored in the project folder.

it is by default, if you dont give a folder it uses project location for all activities that uses a path property.

—we can use EXCEL APPLICATION SCOPE and mention the file name so that it will create a new file in the project folder itself
—and we can mention the same Filename in DELETE activity so that it will get deleted from the same project folder

Cheers @Shikhar_Tandon

Hi @Harshav thanks for response. I tried this but the file is not deleting that’s why i posted the topic

thanks !!

hi @Palaniyappan, thanks for the reply, i have tried this but the bot is stopping and is not deleting the file it is giving error. please help.


1 Like


I think your excel application is still holding the file after your manipulation.
Just do the following

  1. Kill EXCEL application first once you complete the manipulation
  2. Delete after the kill operation

Hope this will work.

What kind of manipulation are you doing that really needs an excel file to exists if you delete it before the process ends? can this be done using only DataTables?

if possible can i have that error screenshot
cheers @Shikhar_Tandon


If you are facing issues deleting a xlsx file using the inbuilt activity you can use Invoke code or invoke code or invoke method.

Code is what I use so here you go.

You create an application as

Excel.Application YourXlObject= new Application();
Path.GetTempPath+YourXlsxFileName - (here is where you create your temporary excel file to be read or copied or created)
In the end for releasing the object you can use the folowing



EXCEL.kill(); // this method accepts the process name and kills it - use it as a last resort.


if (YourXlObject!= null) Marshal.ReleaseComObject(YourXlObject);

The namespaces are - System.IO, System.Diagnostics, Microsoft.Office.Interop.Excel.

These should be used in Invoke code activity and change the language to C# or if you want VB just look up the Syntax in google.

Hope this helps.

Regards :slight_smile: