With an Openfiledialog I'm opening a file, and I want it in Load, change the extension. That is, I'm going to put the "openFileDialog1.Filter" would be just for ".txt" and I want it to change to ".cnf". Thank you.
With an Openfiledialog I'm opening a file, and I want it in Load, change the extension. That is, I'm going to put the "openFileDialog1.Filter" would be just for ".txt" and I want it to change to ".cnf". Thank you.
I do not know why this, but a simple solution is you do like this:
//aqui vai o caminho que você leu no OpenFileDialog
string caminho = "arquivo.txt";
//e aqui você cria uma variável que irá receber o novo caminho.
string novoCaminho = caminho.Remove(caminho.Length -3, 3) + "cnf";
Basically what the above line does is remove the txt
from the file and add cnf
;
Only you will have to save the file for it to have this extension.
Or you can use a native function of C#
:
string caminhoPath = Path.ChangeExtension(caminho, ".cnf");
See more about Path.ChangeExtension () .