To get absolute path of that file use Path.GetDirectoryName(filePath)
and combine it with new file name. You will get new file path
If I understood it correctly, then in your case:
text1.Text
contains full file path. i.e.E:\Files\sample.pdf
text2.Text
contains new file name. i.e. newfilename.pdf
On button_ClickEvent()
you want new file name path. i.e. E:\Files\newfilename.pdf
Implement following logic:
-
Get absolute directory path of sample.pdf
string oldFilePath = Path.GetDirectoryName(text1.Text); //Here you will get "E:\Files\"
-
Then combine path with new file name
string newPath = Path.Combine(oldFilePath, text2.Text) //Here you will get new file path
3
solved Replace filename in textbox [closed]