Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change file name of image path in C#

Tags:

My image URL is like this:

photo\myFolder\image.jpg 

I want to change it so it looks like this:

photo\myFolder\image-resize.jpg 

Is there any short way to do it?

like image 449
zey Avatar asked Jun 19 '13 06:06

zey


1 Answers

This following code snippet changes the filename and leaves the path and the extenstion unchanged:

string path = @"photo\myFolder\image.jpg"; string newFileName = @"image-resize";  string dir = Path.GetDirectoryName(path); string ext = Path.GetExtension(path); path =  Path.Combine(dir, newFileName + ext); // @"photo\myFolder\image-resize.jpg" 
like image 51
Doomjunky Avatar answered Oct 17 '22 07:10

Doomjunky