我正在从FTP服务器下载pdf文件。我需要找到一个字符串并将其替换,但是当我尝试将byte []转换为字符串时。它返回一个非意义的字符串。
WebClient client = new WebClient();
string url = "ftp://myftp.com/doc.pdf";
client.Credentials = new NetworkCredential("username", "password");
byte[] newFileData = client.DownloadData(url);
string s = System.Text.Encoding.UTF8.GetString(newFileData, 0, newFileData.Length);
// This return a odd string
// I would like to replace, for example, all the occurrences of #TEST# to "ABC"
MemoryStream pdfStream = new MemoryStream();
pdfStream.Write(newFileData, 0, newFileData.Length);
pdfStream.Position = 0;
return new FileStreamResult(pdfStream, "application/pdf");
谢谢