Beispiel #1
0
        /// <summary>Touches the given file in the temp directory.</summary>
        /// <param name="tempDirectory">The <see cref="ITempDirectory"/> instance to act on.</param>
        /// <param name="fileName">File name of the file path to generate.</param>
        /// <returns>The full path to the file created or updated.</returns>
        public static string Touch(this ITempDirectory tempDirectory, string fileName)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException("tempDirectory");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            string filePath = tempDirectory.Combine(fileName);

            EnsureDirectory(filePath);
            new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read | FileShare.Write | FileShare.Delete).Dispose();
            return(filePath);
        }
Beispiel #2
0
        /// <summary>Writes text to the given file in the temp directory.</summary>
        /// <param name="tempDirectory">The <see cref="ITempDirectory"/> instance to act on.</param>
        /// <param name="fileName">File name of the file path to generate.</param>
        /// <param name="text">The text to write.</param>
        /// <returns>The full path to the file created or updated.</returns>
        public static string Write(this ITempDirectory tempDirectory, string fileName, string text)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException("tempDirectory");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            string filePath = tempDirectory.Combine(fileName);

            EnsureDirectory(filePath);
            File.WriteAllText(filePath, text, Encoding.UTF8);
            return(filePath);
        }