File.CreateText fails

  • Thread starter Thread starter larzeb
  • Start date Start date
L

larzeb

I am developing a Windows application. The source is stored on a
network share, probably 6 directories deep.

When I say:

File.CreateText("G:\temp\" & _dataSourceInfo.Csv_filename)

the file is created OK on the local disk G in directory temp. However,
when I say:

File.CreateText("%temp%\" & _dataSourceInfo.Csv_filename)

it fails with a Directory not found, and is trying to create:

\\networkShare\...\Application\bin\%temp%\CSV_Filename

Why is this happening? Something to do with security?

TIA Lars
 
I guess I have to do this instead:


Dim tempDirectory As String =
Environment.GetEnvironmentVariable("temp")
File.CreateText(tempDirectory & "\" & _dataSourceInfo.Csv_filename)

but I still don't understand why the runtime is using relative
addressing with the original code.
 
larzeb said:
Dim tempDirectory As String =
Environment.GetEnvironmentVariable("temp")
File.CreateText(tempDirectory & "\" & _dataSourceInfo.Csv_filename)

If you are using more than one environment variable in the string,
'Environment.ExpandEnvironmentVariables' is a good alternative.
 
Back
Top