1

我的问题如下。我想知道是否有可能知道 xml 文件的最后编辑时间。

目前我正在创建我的 xml 并通过以下方式从我的 xml 中读取:

这是写作部分,我正在序列化一个可观察的集合:

XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<DomExistingVacationDays>));
                using (IRandomAccessStream sessionRandomAccess = await VacationRequestOfflineHolidaysFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (IOutputStream sessionOutputStream = sessionRandomAccess.GetOutputStreamAt(0))
                    {
                        using (StreamWriter wr = new StreamWriter(sessionOutputStream.AsStreamForWrite()))
                        {
                            xs.Serialize(wr, _existingHolidaysCollection);
                        }
                    }

                }

这是阅读部分,反序列化可观察的集合:

 XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<DomExistingVacationDays>));
                using (IRandomAccessStream sessionRandomAccess = await VacationRequestOfflineHolidaysFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (IInputStream sessionInputStream = sessionRandomAccess.GetInputStreamAt(0))
                    {
                        using (StreamReader rd = new StreamReader(sessionInputStream.AsStreamForRead()))
                        {
                            _existingHolidaysCollection = xs.Deserialize(rd) as ObservableCollection<DomExistingVacationDays>;
                        }
                    }

                }

我想要实现的是,当 xml 文件中的数据比 let's day 早几天时​​,我不再希望使用它。

所以我可以在 xml 文件中添加一个日期时间,但我想知道这个问题是否没有其他解决方案。

谢谢!

4

2 回答 2

5

您可能会寻找File.GetCreationTime(path)和/或File.GetLastWriteTime(path)(命名空间 System.IO)。

In Win8 UI apps you may want to use StorageFile.GetBasicPropertiesAsync(). The returned BasicProperties contains DateModified. Also StorageFile.DateCreated could be of interest.

于 2013-05-22T08:02:09.810 回答
2

I was able to do this thnx to the help from @JeffRSon by using the StorageFile class. The FileInfo class has been replaced with the StorageFile class in MetroApps. Once i had the storageFile i used following code:

var documentProperties = await OfflineRFile.GetBasicPropertiesAsync();
var dateLastModified = documentProperties.DateModified;

OfflineRFile is my StorageFile.

Thnx for the quick responses

于 2013-05-22T08:38:54.690 回答