I have the following code where it will retrieve data from stream
and print it to text file using streamwriter
and bufferedwriter. By default, it will download the file to the download folder directory in your local pc. The issue that I’m facing right now is I would like to change the directory of the downloaded file to some other directory but I was unable to achieve those. Instead I use System.IO.File.WriteAllText
to achieve those but that’s not what I want since the code below will download two files, one in download folder and another in document folder.
protected override void AddPlainText(Stream outputStream)
{
var records = GetData();
var x = new StringBuilder();
string stamp = DateTime.Now.ToString("dd-MM-yy_HH-mm-ss", CultureInfo.InvariantCulture);
string fileName = "reportTxt_" + stamp + ".txt";
string path = @"C://Users//***//Documents//";
string path2 = @"C:\Users\***\Documents\";
using (var stream = new BufferedStream(outputStream))
{
var writer = new StreamWriter(stream, Encoding.ASCII);
foreach (var r in records)
{
x.AppendLine(r.ToFixedLengthString());
}
var output = x.ToString();
writer.WriteLine(output);
writer.Flush();
//Create File
System.IO.File.WriteAllText(path + fileName, output);
//Calling Transfer Method
SFTP_Connection(fileName, path2);
//Delete file after transfer
if (File.Exists(path + fileName))
{
File.Delete(path + fileName);
}
}
}
Any advice, tips and help will be much appreciated.