5

I need to create a temporary file. I'd like to save it in the temp folder, but I'm not sure what's the best way of getting the full path of this folder. If I use Sitecore.Configuration.Settings.TempFolderPath it only gives me the folder name, not the full path. Is there any helper or similar that gives me this information?

1

2 Answers 2

7

For a temporary file

Actually, Sitecore itself doesn't use TempFolderPath when it needs to create a temporary file.

Looking inside the Sitecore PackageManager classes, Sitecore does this when it needs a temporary file.

string tempFileName = System.IO.Path.GetTempFileName();

Using TempFolderPath

The thing about this setting is; it can be relative to the current web root folder, but it could also be defined as an absolute path (outside your webroot) in which case a MapPath call could fail.

Sitecore has a utility class that deals with this. You can find it in FileUtil, so your code would look like this:

string tempFolder = Sitecore.IO.FileUtil.MapPath(Sitecore.Configuration.Settings.TempFolderPath);

This snippet would work, with both relative and absolute path definitions.

0

you can use :

string tempFullPath = Sitecore.MainUtil.MapPath(Settings.TempFolderPath);

or

string tempFullPath = Sitecore.IO.FileUtil.MapPath(Settings.TempFolderPath);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.