ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

String write/save in file

String save/write in file

Source

public static bool Save(this string text, string pathWithTXTFullfilename)
{
    try
    {
        //write string to file
        System.IO.File.WriteAllText(pathWithTXTFullfilename, text);
        return true;
    }
    catch (Exception)
    {
    }

    return false;
}

Example

String str = "Hi...I am go to save in file";
bool isSaved = str.Save("D:\myfile.txt");

Author: Keyur Panchal

Submitted on: 11 aug. 2015

Language: C#

Type: Satring, Save, Write, File, External

Views: 4294