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

Re: File.CreateText fails by larzeb

larzeb
Sat Jan 22 03:03:58 CST 2005

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.


On Sat, 22 Jan 2005 00:31:13 -0800, larzeb <larzeb@community.nospam>
wrote:

>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


Re: File.CreateText fails by Herfried

Herfried
Sat Jan 22 06:16:55 CST 2005

"larzeb" <larzeb@community.nospam> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>