Friday, February 12, 2010

Code to Read Files from Directory - C#, ASP.NET

public void ReadFile(strFileName)
{
      System.IO.DirectoryInfo obj = new DirectoryInfo(Server.MapPath("FolderName/" + strFileName);
      FileInfo[] Files = obj.GetFiles();

      for (int i = 0; i < Files.Length; i++)
     {
          string FileName = Files[i].Name;
          string FileExtension = FileName.Substring(0, FileName.LastIndexOf("."));
          InsertToDB(FileName, FileExtension ); --Function to save in database
     }
}

No comments: