public async Task <MMM.FileAttachment> AddEventAttachment(string eventId, MMM.FileAttachment fileAttachment) { var attachment = fileAttachment.ConvertObject <Attachment>(); var item = await _graphClient.Me.Events[eventId].Attachments.Request().AddAsync(attachment); return(attachment.ConvertObject <MMM.FileAttachment>()); }
public async void Open(FileAttachment attachment) { var storageFolder = ApplicationData.Current.LocalFolder; try { var newFile = await storageFolder.CreateFileAsync(attachment.Name, CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(newFile, attachment.ContentBytes); if (!await Windows.System.Launcher.LaunchFileAsync(newFile)) { await MessageDialog($"Couldn't start application for {attachment.Name}"); } } catch (Exception ex) { await MessageDialog($"Failure: {ex.Message}"); } }
public async Task<FileAttachment> AddEventAttachment(string eventId, FileAttachment attachment) { string uri = EventsFolder + eventId + "/attachments"; return await GetHttpHelper().PostItemAsync<FileAttachment>(uri, attachment); }
private void AttachmentDeleted(FileAttachment item) { var removed = _attachments.FirstOrDefault(x => x.Name == item.Name); _attachments.Remove(removed); OnPropertyChanged(() => HasAttachments); }
public void Open(FileAttachment attachment) { var context = Forms.Context; File file; try { var dir = Android.OS.Environment .GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads); file = new File(dir, attachment.Name); using (var stream = new FileOutputStream(file)) { stream.Write(attachment.ContentBytes); } } catch (Exception ex) { var message = $"Couldn't download {attachment.Name}: {ex.Message}"; Toast.MakeText(context, message, ToastLength.Short).Show(); return; } var uri = Android.Net.Uri.FromFile(file); var ext = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(uri.ToString()); var mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(ext); var intent = new Intent(Intent.ActionView); // Using just SetType method doesn't appear to work if (string.IsNullOrEmpty(mimeType)) { intent.SetDataAndType(uri, "application/*"); } else { intent.SetDataAndType(uri, mimeType); } var available = context.PackageManager .QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.MatchDefaultOnly); if (!available.Any()) { var message = $"No apps found for {attachment.Name}"; Toast.MakeText(Forms.Context, message, ToastLength.Short).Show(); } else { try { context.StartActivity(intent); } catch (Exception ex) { var message = $"Couldn't start activity: {ex.Message}"; Toast.MakeText(Forms.Context, message, ToastLength.Short).Show(); } } }