File.WriteTextAsUTF8_ToTemp Method

Writes the text to file as UTF-8 to temp folder.
public static string[] WriteTextAsUTF8_ToTemp( 
string text
string targetFile 
)
This language is not supported or no code example is available.

Parameters

text
string

The text.

targetFile
string

The target file.

Return Value

string[]

An array of string (File name and File path).

public static string[] WriteTextAsUTF8_ToTemp(string text,
     string targetFile)
 {
     string fileName = NameGenerator(targetFile, "txt");
     string filePath = $@"{Path.GetTempPath()}\{fileName}";
     using (FileStream fs = System.IO.File.OpenWrite(filePath))
     {
         var data = text;
         byte[] bytes = Encoding.UTF8.GetBytes(data);
         fs.Write(bytes, 0, bytes.Length);
     }
     return new string[] { fileName, filePath };
 }
					
This language is not supported or no code example is available.

.NET Framework

Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

.NET Core

Supported in: 5.0+, 6.0+

In this article

Definition