rename a file in asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,
i have a file whose name is "clientStmt.txt" in 'C:\stmt\' folder.
I want to rename and change the extension while renaming as below.
i.e. i want to change the file 'C:\stmt\clientStmt.txt' to
'C:\stmt\clientStmt.XLS'
(to xls extension.).
does any body know how to do it in asp.net.

thanks,
hari.
 
To simply change extension? No, but I have not tried.

You can open a streamreader and a streamwriter. The reader reads the .txt
and the writer writes the .xls. You can then delete the .txt. Not an optimal
solution, but it will work.

I would imagine you could simply change the extension with a FileInfo or
File object, but I have never done it.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
So, you just want to change the extension? If yes:

// In C#
FileInfo fi = new FileInfo (@"C:\stmt\clientStmt.txt");
fi.MoveTo(Path.GetDirectoryName(fi.FullName) + "\\" +
Path.GetFileNameWithoutExtension(fi.FullName) + ".xls");

HTH

hi,
i have a file whose name is "clientStmt.txt" in 'C:\stmt\' folder.
I want to rename and change the extension while renaming as below.
i.e. i want to change the file 'C:\stmt\clientStmt.txt' to
'C:\stmt\clientStmt.XLS'
(to xls extension.).
does any body know how to do it in asp.net.

thanks,
hari.
 
In addition to the suggestion to use the FileInfo object,
you will need to make sure that your ASP.NET application has permissions to
change a file in the directory c:\stmt

--- Nick
 
Back
Top