We help IT Professionals succeed at work.

How to change the file extension to upper case in c#?

1,241 Views
Last Modified: 2014-11-24
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:
 FormName = "Form" + form + ".PDF";
fsOutput = new FileStream(TemplatePath + FormName, FileMode.Create,                                                  FileAccess.Write);
objDoc.Generate(fsoutput);

Open in new window

Comment
Watch Question

Senior Software Engineer
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
The first one works for me but it displays the string as "FormForm12345.PDF" and If I modify the code to resolve it does not work
Miguel OzSenior Software Engineer
CERTIFIED EXPERT
Top Expert 2009

Commented:
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:
FormName = String.Format(CultureInfo.CurrentCulture, "{0}.PDF", form);

Open in new window

thus, FormName=  "Form12345.PDF"

Author

Commented:
I did modify the string the same way you did and it returned me 1234.PDF as file name
Vel EousResearch & Development Manager
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Miguel OzSenior Software Engineer
CERTIFIED EXPERT
Top Expert 2009

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.