Example #1
0
        /// <summary>
        /// Creates a file with the specified name in a new, randomly named folder.
        /// Dispose will dispose of the folder (and any subsequently added content) as well as the temp file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static TempFile WithFilenameInTempFolder(string fileName)
        {
            var tempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());

            Directory.CreateDirectory(tempFolder);
            var path   = System.IO.Path.Combine(tempFolder, fileName);
            var result = TempFile.TrackExisting(path);

            result._folderToDelete = tempFolder;
            return(result);
        }
Example #2
0
        /// <summary>
        /// Used to create a temporary filename in the same folder as another file.
        /// </summary>
        /// <param name="inputPath">path to an (existing) file</param>
        public static TempFile InFolderOf(string inputPath)
        {
            var folder = System.IO.Path.GetDirectoryName(inputPath);

            if (String.IsNullOrEmpty(folder))
            {
                folder = ".";
            }
            var path = System.IO.Path.Combine(folder, System.IO.Path.GetRandomFileName());

            return(TempFile.TrackExisting(path));
        }