temp directory question

A

Aussie Rules

Hi,

In my application I need to write an XML file to disk, but am concerned that
permission might be a problem.

The file only needs to be written out and used for another reason and can
then be deleted.

I was thinking about using the windows/system temp directory as the
location, as I guess that a directory where my application shouldn't have an
issue writting to.

Is this the best location for this file to go? and how do I determine what
the temp directory is ?

Thanks
 
M

Michel Posseth [MCP]

The location and the purpose look suitable to me
you can use My.Computer.FileSystem.SpecialDirectories to find the temp dir
and other "special directories"

you can also use System.Environment.GetFolderPath() to get the path of any
of the windows folders as listed in the System.Environment.SpecialFolder
enumeration.

hth

Michel
 
K

kimiraikkonen

Hi,

In my application I need to write an XML file to disk, but am concerned that
permission might be a problem.

The file only needs to be written out and used for another reason and can
then be deleted.

I was thinking about using the windows/system temp directory as the
location, as I guess that a directory where my application shouldn't have an
issue writting to.

Is this the best location for this file to go? and how do I determine what
the temp directory is ?

Thanks

If you have any difficulty about writing to a specific folder such as
temp (plus you may able to write), create your own temp folder in your
application folder then delete folder / file after operation has
finished.

For example when you need a folder temporarily, create a new one
using:
System.IO.Directory.CreateDirectory("c:\your_app\your_folder")

Then you can delete folder fairly after the directory is not needed
anylonger using:
(usually when formclosing event is fired)
System.IO.Directory.Delete("c:\your_app\your_folder")

Therefore you have a folder that's created and deleted temporarily,
just my opinion.

Regards,

Onur Güzel
 
H

Herfried K. Wagner [MVP]

Aussie Rules said:
Is this the best location for this file to go? and how do I determine what
the temp directory is ?

'System.IO.Path.GetTempPath'.
 
K

kimiraikkonen

This will cause you a problem in Windows Vista if your application is
installed in ProgramFiles. A better choice would be to put the file in the
local app data, which is under the user's profile --
Environment.SpecialFolder.LocalApplicationData.

RobinS.
GoldMail.com









If you have any difficulty about writing to a specific folder such as
temp (plus you may able to write), create your own temp folder in your
application folder then delete folder / file after operation has
finished.

For example when you need a folder temporarily, create a new one
using:
System.IO.Directory.CreateDirectory("c:\your_app\your_folder")

Then you can delete folder fairly after the directory is not needed
anylonger using:
(usually when formclosing event is fired)
System.IO.Directory.Delete("c:\your_app\your_folder")

Therefore you have a folder that's created and deleted temporarily,
just my opinion.

Regards,

Onur Güzel

I'm not familiar with Vista at the moment so i don't know what you
meant about what it causes, but you must be able to create and delete
your own folders with no problem in XP and olders in program files.
Maybe program files is protected in Vista. Thanks for the info.

But with same logic you can dynamically create / delete a folder in a
writable location such as you mentioned.
 
C

Cor Ligthert [MVP]

Kimi,

Just the simple way as Herfried wrote is in my idea the solution here.

Cor

"kimiraikkonen" <[email protected]> schreef in bericht
This will cause you a problem in Windows Vista if your application is
installed in ProgramFiles. A better choice would be to put the file in
the
local app data, which is under the user's profile --
Environment.SpecialFolder.LocalApplicationData.

RobinS.
GoldMail.com









If you have any difficulty about writing to a specific folder such as
temp (plus you may able to write), create your own temp folder in your
application folder then delete folder / file after operation has
finished.

For example when you need a folder temporarily, create a new one
using:
System.IO.Directory.CreateDirectory("c:\your_app\your_folder")

Then you can delete folder fairly after the directory is not needed
anylonger using:
(usually when formclosing event is fired)
System.IO.Directory.Delete("c:\your_app\your_folder")

Therefore you have a folder that's created and deleted temporarily,
just my opinion.

Regards,

Onur Güzel

I'm not familiar with Vista at the moment so i don't know what you
meant about what it causes, but you must be able to create and delete
your own folders with no problem in XP and olders in program files.
Maybe program files is protected in Vista. Thanks for the info.

But with same logic you can dynamically create / delete a folder in a
writable location such as you mentioned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top