Rename a File on the Disk or Local File System using C#
The following code will rename a file called temp.txt to tempnew.txt
using System.IO;
try
{
FileInfo TheFile = new FileInfo("C:\\" + "temp.txt");
if (TheFile.Exists)
{
File.Move("C:\\" + "temp.txt", "C:\\" + "tempnew.txt");
}
else
{
throw new FileNotFoundException();
}
}
catch (FileNotFoundException ex)
{
lblDisplay.Text += ex.Message;
}
catch (Exception ex)
{
lblDisplay.Text += ex.Message;
}
Related Articles
- String Replace Function in C#
- Try Catch Statements for Error Handling in Asp.Net & C#
- Send Email Attachments from a Form using Asp.Net and C#
- Create a Checkbox List Web Control Using Asp.Net & C#
- VBA Code to Call Windows API File Open Dialog Box in Microsoft Access
- Obtain Values of Query String using C#
- Prevent Framing of your Website using Html
- How to Fix the Background Image on a Webpage using Html
