FileMethods

 var currentDirectory = System.IO.Directory.GetCurrentDirectory();

var filePath = @"\Resources\Templates\SOP.docx";


 string filepath = currentDirectory + "" + filePath;


var fileName = "BIMS_" + "" + mprnumber + ".docx";


currentDirectory = currentDirectory + "\\Resources\\Documents";


var filepath = Path.Combine(Path.Combine(currentDirectory), fileName);


1.To Read the Data From File

byte[] bytes = System.IO.File.ReadAllBytes(filepath);

// Read the contents of the file

        string[] lines = File.ReadAllLines(filePath);


2.return File(bytes, contentType, fileName);


3.To Write Data into File

System.IO.File.WriteAllBytes(printfilepath, bytes);

// Write the updated contents back to the file

        File.WriteAllLines(filePath, lines);


4.To Check Exist a File With Same Name

System.IO.File.Exists(filepath)


5.To Delete a File

System.IO.File.Delete(filepath);


6.To Copy a file

 File.Copy(filepath, Outputpath);


Comments