O'Reilly logo

Windows Application Development Cookbook by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Renaming a file

Just like folders, files could also be easily renamed using the RenameAsync method, which is explained in this recipe.

As an example, you will modify the project from the previous recipe by adding a Rename a file button. Once you click on it, the Notes.txt file (from the Book directory) should be renamed Note.txt.

Getting ready

To step through this recipe, you need the project from the previous recipe.

How to do it...

To see how to rename a given file, perform the following steps:

  1. Add the Rename a file button to the page by modifying the content of the MainPage.xaml file as follows:
            <Page (...)> 
                <StackPanel> (...) 
                    <Button  
                        Content="Rename a file" 
                        HorizontalAlignment="Center"  
                        VerticalAlignment="Center" 
                        Click="BtnRenameFile_Click" /> <TextBlock ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required