using System;
using System.IO;
namespace Umbraco.Core.IO
{
public static class IOHelperExtensions
{
///
/// Tries to create a directory.
///
/// The IOHelper.
/// the directory path.
/// true if the directory was created, false otherwise.
public static bool TryCreateDirectory(this IIOHelper ioHelper, string dir)
{
try
{
var dirPath = ioHelper.MapPath(dir);
if (Directory.Exists(dirPath) == false)
Directory.CreateDirectory(dirPath);
var filePath = dirPath + "/" + CreateRandomFileName(ioHelper) + ".tmp";
File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it.");
File.Delete(filePath);
return true;
}
catch
{
return false;
}
}
public static string CreateRandomFileName(this IIOHelper ioHelper)
{
return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8);
}
}
}