Click here to Skip to main content
15,896,349 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
So this is my code:
My.Computer.FileSystem.RenameFile("C:\j\Application.exe", Path.GetRandomFileName())
.. The extension changes to something random, which I don't want. I want the extension to be .pdf while using the code Path.GetRandomFileName(). Can anybody help me with the right code, please?

What I have tried:

Dim myFiles As String()

myFiles = IO.Directory.GetFiles("C:\Application.exe", Path.GetExtension")

Dim newFilePath As String

For Each filepath As String In myFiles

filepath.Replace(".exe")

System.IO.File.Move(filepath, newFilePath)

Next

End Sub

End Class
Posted
Updated 3-Aug-18 23:57pm
v7

/*Convert file format to png*/


string newfilename , 
 string filename = "~/Photo/"  + lbl_ImgPath.Text.ToString();/*get filename from specific path where we store image*/
 string newfilename = Path.ChangeExtension(filename, ".png");/*Convert file format from jpg to png*/
 
Share this answer
 
Comments
Richard Deeming 6-Aug-18 11:47am    
This question was already solved over a year ago.

Stick to answering recent questions.
Path.GetRandomFileName()[^] returns a string, so probably the best way to manipulate it...
If you do not care for the 8.3 format:
C#
string.Format("{0}.exe", Path.GetRandomFileName().Replace(".", string.Empty));

If the 8.3 format is important:
C#
string.Format("{0}.exe", Path.GetRandomFileName().Substring(0, 8));
 
Share this answer
 
Comments
[no name] 16-Jul-17 10:30am    
Thank you for your reply. :)

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