Monday, 27 May 2013

How to delete file from folder using C# code

How to delete file from folder using C# code


Step 1: Create your website first in asp.net and create one default.aspx page.

Step 2: Open file source code .cs file or .vb file and paste below code in that file


//add System.IO package
using System.IO


// specify the path of images
string imageFolderLocation= @"c:\imageFolder\";



// get all files from the specify location by using Directory inbuilt library.
string[] Imagefiles = Directory.GetFiles(imageFolderLocation);



//print the all file location to your page using response.write command
 for (int i = 0; i < Imagefiles .Length; i++)
        {
          
             Response.Write("File is deleted at location : -  " + destination[i]);
             File.Delete( Imagefiles[i]);
        }

Step 3 : This way you can access all files from specific folder and you can do delete file from  folder..etc








No comments:

Post a Comment

Thank you for your interest .