Live Chat Icon For mobile
Live Chat Icon

What is the best way to rename a file on the webserver in code

Platform: ASP.NET| Category: Files

Use namespace System.IO

VB.NET


File.Move('C:\Dir1\SomeFile.txt', 'C:\Dir1\RenamedFileName.txt')

C#


File.Move(@'C:\Dir1\SomeFile.txt', @'C:\Dir1\RenamedFileName.txt')

Refer

Note: In a Web application, the code is running in the context of the machine\ASPNET account, which has limited privileges. If the error you are getting pertains to permissions, you might need to grant to the machine\ASPNET account the rights to create and delete files in the directory where you’re working. Note that this could be a security issue.

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.