System.IO.IsolatedStorage.IsolatedStorageFile.GetCreationTime C# (CSharp) Method

GetCreationTime() public method

public GetCreationTime ( string path ) : DateTimeOffset
path string
return DateTimeOffset
        public DateTimeOffset GetCreationTime(string path)
        {
            if (path == null)
                throw new ArgumentNullException(nameof(path));

            if (path == string.Empty)
            {
                throw new ArgumentException(SR.Argument_EmptyPath, nameof(path));
            }

            EnsureStoreIsValid();

            try
            {
                return new DateTimeOffset(File.GetCreationTime(GetFullPath(path)));
            }
            catch (UnauthorizedAccessException)
            {
                return new DateTimeOffset(1601, 1, 1, 0, 0, 0, TimeSpan.Zero).ToLocalTime();
            }
        }

Same methods

IsolatedStorageFile::GetCreationTime ( string path ) : System.DateTimeOffset

Usage Example

Esempio n. 1
0
        private static void CleanupLogs(IsolatedStorageFile store, string logFolder)
        {
            var files = store.GetFileNames(logFolder);
            var fileCount = files.Count();
            if (fileCount > MAX_FILE_COUNT - 1)
            {
                var filesAgeAsc = from file in files
                                  let age = store.GetCreationTime(file)
                                  orderby age ascending
                                  select file;
                var deleteFiles = filesAgeAsc.Take(fileCount - MAX_FILE_COUNT + 1);

                foreach (var file in deleteFiles)
                {
                    var filePath = Path.Combine(logFolder, file);
                    store.DeleteFile(filePath);
                }
            }
        }