using System.IO; public void AddFile(string path) { var fileName = Path.GetFileName(path); var destPath = Path.Combine("C:\\MyFiles", fileName); File.Copy(path, destPath); }
using System.IO; using System.Text; public void AppendToFile(string path, string content) { using (StreamWriter writer = File.AppendText(path)) { writer.WriteLine(content); } }This code example shows how to add text to an existing file. The AppendToFile method takes a path to the existing file and the content to be added as parameters. It uses a StreamWriter object to write the content to the file. The StreamWriter object is created using the File.AppendText method, which opens the file in append mode and returns a StreamWriter object that can be used to write to the file.