1

I am facing a special problem concerning the environment variable TMP on my system, I think.

This variable is defined like this:

TMP=c:\profiles\myUser\LOKALE~1\temp

Writing to this location via the .net application is not possible whereas through the windows explorer I can easily create files.

Any ideas how to solve this problem?

Regards, MacX

MacX
  • 587
  • 5
  • 16
  • 2
    Are you getting an exception? If yes what? Which user you are running your application under? Does it have permissions to write to `c:\profiles\myUser\LOKALE~1\temp`? – Darin Dimitrov Jan 21 '11 at 13:07
  • I don't understand, are you trying to create a temporary file? if so you can use Path.GetTempPath or GetTempFile or similar, without caring on where the file is really saved. – Davide Piras Jan 21 '11 at 13:09
  • I am trying to save a temporary file for displaying it to the user. But I am not able to store it with the Application. Instead within the explorer I am able to write to the directory. Maybe this problem relies to the character '~' within the environment variable? the variable TMP is the same as TMPDIR. – MacX Jan 21 '11 at 13:30

2 Answers2

4

Actually according to the MSDN:

Referring to Path.GetTempPath
This method checks for the existence of environment variables in the following order and uses the first path found:

  • The path specified by the TMP environment variable.
  • The path specified by the TEMP environment variable.
  • The path specified by the USERPROFILE environment variable.
  • The Windows directory.

It doesn't specify if it checks if the running process has write access so depending on the process rights it may not be able to write.

Cristian T
  • 2,245
  • 3
  • 25
  • 45
0

the problem is not the variable itself, but the way I access the files to open it. I try to open the files via a console-parameter, where blanks a treated as seperators, if the paths are not quotet.

excel.exe c:\path tofile\excelfile.xls

should be quoted and look like this

excel.exe "c:\path tofile\excelfile.xls"

That's it.

Because I didn't write the app myself, I had to look this part up in the source code. But thanks a lot, for the hints.

MacX

MacX
  • 587
  • 5
  • 16