Excel Application Scope ,How to set path of file?

For Excel Application Scope ,How to set path of file?
I want to copy data from datatable to excel file with path : "C:\Users:" +environment.UserName + "\Desktop\Output" + “output.xls”

So,under Excel Application Scope workbookpath = "C:\Users:" +environment.UserName + "\Desktop\Output" + “output.xls”

but it’s still error “Excel Application Scope: The given path 's format is not supported”
What should I do?

Use String.Concat( “C:\Users\”, Environment.UserName, “\Desktop\Output\output.xls”).

1 Like

@Anthony_Humphries, @Supakinee_Navawong_na_ayu

Path.Combine

I prefer Path.Combine to String manipulations; you don’t have the burden of directory separator match/mismatch for example:

Path.Combine("C:\Users", Environment.UserName, "Desktop\Output\output.xlsx")

and the following, with an extra "\" will be the same:

Path.Combine("C:\Users\", Environment.UserName, "Desktop\Output\output.xlsx")

Environment.ExpandEnvironmentVariables

In that particular case, I’d rather use the following approach. In your configuration:

ExcelPath = "%USERPROFILE%\Desktop\Output\output.xlsx"

And in your workflow:

excelPath = in_Config("ExcelPath").ToString
path = Environment.ExpandEnvironmentVariables(excelPath)

or simply:

path = Environment.ExpandEnvironmentVariables(in_Config("ExcelPath").ToString)

Thank you for all of your helps. It’s already work.
:slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.