Thursday, January 21, 2016

Deleting Files in ASP.NET C#

Simplest way to delete files in asp.net C#

if ((System.IO.File.Exists(fileName)))
                {
                    System.IO.File.Delete(fileName);
}


This is a simple code snippet in asp.net that can be used to delete files from any directory.
In here variable "fileName" is the specific path to the file.

Ex: If want to delete a file called "hello.pdf" in "upload" folder which is in my C drive, file name should be full path to that file "C:\upload\hello.pdf"


No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...