public static string Create() { string path = null; if (_path != null) { // create file in user specified path path = Path.Combine(_path, Guid.NewGuid().ToString()); File.Create(path).Close(); } else { // allow OS to create file in system temp path path = Path.GetTempFileName(); } try { // set temporary file attribute so that the file system // will attempt to keep all of the data in memory File.SetAttributes(path, new FileInfo(path).Attributes | FileAttributes.Temporary); } catch { // sometimes fails with invalid argument exception } return(path); }
/// <summary> /// Moves file and updates internal reference. /// /// Calling this method will also remove set the <see cref="IsTempFile"/> property to <c>False</c>. /// </summary> /// <param name="dstFileName"></param> public void Move(string dstFileName, bool overwrite = false) { // delete if overwriting; let File.Move thow IOException if not if (File.Exists(dstFileName) && overwrite) { File.Delete(dstFileName); } File.Move(Name, dstFileName); Name = Path.GetFullPath(dstFileName); IsTempFile = false; }