Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
info.Photo_Compteur = fileName;


What I have tried:

I would like to rename the file by adding the primary key field for each file
Posted
Updated 6-Feb-20 9:36am
Comments
Richard MacCutchan 6-Feb-20 12:59pm    
What is stopping you?
Member 14663996 6-Feb-20 13:02pm    
the syntax
Patrice T 6-Feb-20 13:11pm    
And you are unlucky, in your place, internet do not allow you to read language documentation ?
Member 14663996 6-Feb-20 14:53pm    
fileName=String.Concat(fileName, "info.Numero");
phil.o 6-Feb-20 13:14pm    
Please explain which syntax you used that did not yield proper results.

1 solution

C#
fileName=String.Concat(fileName, "info.Numero");
Imagine the filename is "file.txt", your way would lead to the filename "file.txtinfo.Numero".
Here you want the value of the Numero property of the info variable. You passed a string instead. You should not put that between double quotes.
Moreover, files often have extensions. You may want to add the number after the name only, not after the extension.
A more suitable way may be
C#
fileName = string.format
(
   "{0}{1}{2}",
   Path.GetFileNameWithoutExtension(fileName),
   info.Numero,
   Path.GetExtension(fileName)
);
With this method, you would get "file1.txt" instead.
 
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