none
Change text content in code?

    Question

  • How i can change a text content in a code?

    I want to replace that text with the text from a file.txt

    i know how to change the text: name.Content = "newText", but how do i get the new text from a file.txt?



    Sunday, April 23, 2017 6:17 PM

Answers

All replies

  • I'd have a look at streamreader - https://msdn.microsoft.com/en-us/library/system.io.streamreader

    read from text file, hold text in string then display it

    Sunday, April 23, 2017 8:42 PM
  • Hi Ailincai Rares,

    I agree with Daniel Loudon.
    (1) in order to get a new text from an input file, user System.IO.StreamReder
    (2) save the new text somewhre (variable, control on Form, etc.)
    (3) read a target file and replace text and save the file
    ______________
    Ashidacchi
    Monday, April 24, 2017 1:46 AM
  • You can do it by using the Read All Text method.

    Refer : https://msdn.microsoft.com/en-us/library/system.io.file.readalltext(v=vs.110).aspx

    name.Content = System.IO.File.ReadAllText("File Path");


    --------------------------------------------------------

    Surender Singh Bhadauria

    My Blog

     

    Monday, April 24, 2017 8:29 AM
  • Hi Ailincai Rares,

    I agree with Daniel Loudon.
    (1) in order to get a new text from an input file, user System.IO.StreamReder
    (2) save the new text somewhre (variable, control on Form, etc.)
    (3) read a target file and replace text and save the file
    ______________
    Ashidacchi

    I made this, thanks Everyone!

            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                using (var client = new WebClient())
                {
                    client.DownloadFile("urlToMyFile", "GameVersion_Log.log");
                }

                string version = System.IO.File.ReadAllText(path);

                GameVersion.Content = version;
            }

            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                System.IO.File.Delete(path);
            }
    Monday, April 24, 2017 2:45 PM