Beispiel #1
0
        public async void Create()
        {
            // Create sample file; replace if exists.
            Windows.Storage.StorageFolder storageFolder =
                Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("Untitled.txt",
                                                                                         Windows.Storage.CreationCollisionOption.ReplaceExisting);

            File = await _FileService.LoadAsync(sampleFile);

            await sampleFile.DeleteAsync(Windows.Storage.StorageDeleteOption.PermanentDelete);
        }
        //override the on navigated to at the page level as well to handle the jump list.
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //the parameter being passed from the on launched event handler in app
            //is the file itself.
            // verify that the file is of type storage file then pass it to the view model via
            // the service as normal.
            // this loads the contents of the file into the view from the jump list.
            if (e.Parameter is StorageFile)
            {
                var service = new Services.FileService();
                var model   = await service.LoadAsync(e.Parameter as StorageFile);

                ViewModel.File = model;
            }
        }
Beispiel #3
0
        public async void Open()
        {
            // prompt a picker
            var picker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
            };

            picker.FileTypeFilter.Add(".txt");
            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                await new Windows.UI.Popups.MessageDialog("No file selected.").ShowAsync();
            }
            else
            {
                File = await _FileService.LoadAsync(file);
            }
        }
Beispiel #4
0
        public async void Open()
        {
            var picker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
            };

            picker.FileTypeFilter.Add(".txt");

            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                await new Windows.UI.Popups.MessageDialog("No file selected !").ShowAsync();
            }
            else
            {
                File = await _fileService.LoadAsync(file);
            }


            List <string> fileProperties = new List <string>();

            fileProperties.Add("File name: " + file.Name);
            fileProperties.Add("File type: " + file.FileType);

            // Get file's basic properties.
            Windows.Storage.FileProperties.BasicProperties basicProperties =
                await file.GetBasicPropertiesAsync();

            string fileSize = string.Format("{0:n0}", basicProperties.Size);

            fileProperties.Add("File size: " + fileSize + " bytes");
            fileProperties.Add("Date modified: " + basicProperties.DateModified);

            // Define property names to be retrieved for Extended properties.
            const string dateAccessedProperty = "System.DateAccessed";
            const string fileOwnerProperty    = "System.FileOwner";

            var propertyNames = new List <string>();

            propertyNames.Add(dateAccessedProperty);
            propertyNames.Add(fileOwnerProperty);

            // Get extended properties.
            IDictionary <string, object> extraProperties =
                await file.Properties.RetrievePropertiesAsync(propertyNames);

            // Get date-accessed property.
            var propValue = extraProperties[dateAccessedProperty];

            if (propValue != null)
            {
                fileProperties.Add("Date accessed: " + propValue);
            }

            // Get file-owner property.
            propValue = extraProperties[fileOwnerProperty];
            if (propValue != null)
            {
                fileProperties.Add("File owner: " + propValue);
            }

            FileProperties = fileProperties;
        }