Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two strings

1 . string path // contains the path to which the file is saved

2 . string name // contains the name of the file which changes frequently

now i have to save the file with .xlsx format , how can i achieve this ???
:(( :(( :(( :((
what i have done is

xlWorkBook.SaveAs(path + "" +fName+".xlsx");

but am getting errors :(

please help me :)
OriginalGriff 30-Jan-11 6:04am    
Please don't post replies with "Add an Answer", use the "Add Comment" feature instead.
When add an answer, nobody is notified - only you could be.
When you add a comment, the person who wrote the answer gets an email. This should mean faster responses for you, as we aren't guaranteed to "check back" on our existing answers.
I have moved your answer to a comment, and deleted the answer.

BTW: You are welcome!

OK, now the correct answer:

string fileName = string.Format(
    System.IO.Path.DirectorySeparatorChar, //important: '\' is incompatible!

Other answers does not take into account that the directory separator in the form of '\' is not portable — so I could not accept them. In particular, it won't work on Unix (yes, support of Unix is a part of CLI standard, in practice, this code can be used on Linux, Unix, MAC, etc. using Mono).

Also, string.Format is reportedly of better performance then a set of string concatenations (using '+').

Thank you for attention to these details.

Share this answer
Espen Harlinn 31-Jan-11 15:22pm    
5+ for the portable answer :)
Try putting a '\' character between the path and the file name.

If that doesn't fix it, then we need to know the error message / exception detail.
Share this answer
OriginalGriff 30-Jan-11 6:01am    
The OP Wrote:
"Thank you guys , i got with answer
Improve Answer link | Posted 20 mins ago
Espen Harlinn 30-Jan-11 6:29am    
5+ a happy "customer" :)
Sergey Alexandrovich Kryukov 30-Jan-11 22:35pm    
I would not be happy -- see my correction.
Sergey Alexandrovich Kryukov 30-Jan-11 22:34pm    
Griff, sorry, you have one incorrectness: '\' is not portable. Please see my 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