Esempio n. 1
0
        /// <summary>
        /// Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail.
        /// </summary>
        /// <param name="mode">The enum value that describes the purpose of the thumbnail and determines how the thumbnail image is adjusted.</param>
        /// <returns>When this method completes successfully, it returns a <see cref="StorageItemThumbnail"/> that represents the thumbnail image or null if there is no thumbnail image associated with the file.</returns>
        public Task <StorageItemThumbnail> GetThumbnailAsync(ThumbnailMode mode)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return(Task.Run <StorageItemThumbnail>(async() =>
            {
                return await _file.GetThumbnailAsync((Windows.Storage.FileProperties.ThumbnailMode)mode);
            }));
#else
            if (ContentType.StartsWith("video"))
            {
                return(StorageItemThumbnail.CreateVideoThumbnailAsync(this));
            }

            else if (ContentType.StartsWith("image"))
            {
                return(StorageItemThumbnail.CreatePhotoThumbnailAsync(this));
            }

            return(Task.FromResult <StorageItemThumbnail>(null));
#endif
        }
Esempio n. 2
0
        /// <summary>
        /// Attaches files. Let´s the user choose file(s) to attach to the mail
        /// </summary>
        public async void AttachFile()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            picker.FileTypeFilter.Add("*");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            //Checks if the file has already been added
            foreach (var tempFile in FileList)
            {
                if (tempFile.FileName.Equals(file.Name))
                {
                    DisplayDialog("Error attaching file", "This file has already been attached! Try again!");
                    return;
                }
            }

            if (file != null)
            {
                //For use when sending the mail (adds file to the list of attached files)
                byte[] byteArray = await HelperUtils.GetBytesAsync(file);

                MailHandler.attachedFiles.Add(file.Name, byteArray);

                //Adds AttachedFile for displaying in the GridView
                FileList.Add(new AttachedFile
                {
                    FileName  = file.Name,
                    Thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView)
                });

                txtAttachedFiles.Text = "Attached files:";
            }
        }