'Download a file without using return

I'm doing a program in asp.net C# that I need to download a file and continue running the program to delete the file that I creat, but the only whay I'm able to download the file is using a retun of a FileContentResult, like this

     documento.Save(Path);     
     byte[] fileBytes = GetFile(Path);
     FileContentResult resultado = File(
     fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, ""+name+"");
     return resultado;

but if i try to delete the file before giving the retun give me an error because i'm still with the variable filecontentresult open then i'd like to do something like that

documento.Save(Path);     
byte[] fileBytes = GetFile(Path);
FileContentResult file = File(
fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, ""+name+"");
//Download the file without return to the view
System.IO.File.Delete(Path);


Solution 1:[1]

You need to close the file after creating and writing in it, then you can delete.

using (var myFile = File.Create(myPath))
{
   // interact with myFile here, it will be disposed automatically
}

//then you can delete here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amjad S.