developer2012
asked on
How to change the file extension to upper case in c#?
I am generating PDF Files with the extension "pdf" in small letters and requirement is to change it to PDF (All in upper case). When I generate the files and debug, it shows the intended output and after generating it again displays the same lower case extension.
I have 34 files in the folder and it does change the file for only three files and rest of them lower case.
Can anyone please guide me how to resolve this issue?
here is my code:
I have 34 files in the folder and it does change the file for only three files and rest of them lower case.
Can anyone please guide me how to resolve this issue?
here is my code:
FormName = "Form" + form + ".PDF";
fsOutput = new FileStream(TemplatePath + FormName, FileMode.Create, FileAccess.Write);
objDoc.Generate(fsoutput);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What exactly do you need?
e.g. if form="Form12345" then FormName= "FormForm12345.PDF" as per original code.
if you are trying to avoid duplicating word "form" just modify the format string like:
e.g. if form="Form12345" then FormName= "FormForm12345.PDF" as per original code.
if you are trying to avoid duplicating word "form" just modify the format string like:
FormName = String.Format(CultureInfo.CurrentCulture, "{0}.PDF", form);
thus, FormName= "Form12345.PDF"
ASKER
I did modify the string the same way you did and it returned me 1234.PDF as file name
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the value of the form variable?
It seems that in your last example form=1234, if that is the case you need to use my original code.
My original String.Format code is doing two jobs:
- Creating an invariant name that you can use for your filename.
- Adding a prefix "Form" and a suffix ".PDF" to your form variable by using the format string ("Form{0}.PDF" )
I proposed that solution because the original code was (FormName = "Form" + form + ".PDF";), if your needs have changed please feel free to modify the format string to your current needs.
It seems that in your last example form=1234, if that is the case you need to use my original code.
My original String.Format code is doing two jobs:
- Creating an invariant name that you can use for your filename.
- Adding a prefix "Form" and a suffix ".PDF" to your form variable by using the format string ("Form{0}.PDF" )
I proposed that solution because the original code was (FormName = "Form" + form + ".PDF";), if your needs have changed please feel free to modify the format string to your current needs.
ASKER