Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiee guys
I have a que. plz give me reply
how to change the extension of a file using C#
eg:- .dat file to .xls


Thanxx in advance
Posted
Comments
codeninja-C# 12-Dec-12 9:19am    
may i know why you want this?Is that file contains a clear value or encoded value? are you try to open that file in wordpad?
--Sj

Refer Below Link
Hope it will help full for you.
Link 1[^]

Link 2
[^]
all the best
 
Share this answer
 
hmm.. let me explain.

It is not possible to change a filename (nor the extension) of a file with .NET. This just is not implemented.

BUT you can do as follows: Copy the content of the existing file into a new file (name it as you want), afterwards delete the source file.

C#
private void RenameFile(string filename, string newFileName)
{
    File.WriteAllText(newFileName, File.ReadAllText(filename, Encoding.Default));
    File.Delete(filename);
}


regards Patrick
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900