private string GetReqsDir() { string cacheDir = fileSystem.GetFilesDir(); string reqPath = fileSystem.JoinPaths(cacheDir, "reqs"); return(reqPath); }
private async void LstAttachments_ItemSelected(object sender, SelectedItemChangedEventArgs e) { try { if (e.SelectedItem == null) { return; } Attachment att = (Attachment)e.SelectedItem; lstAttachments.SelectedItem = null; string attDir = GetAttachmentDir(this.inboxMessage); string file = fileSystem.JoinPaths(attDir, FileHelper.SanitizeFileName(att.NomeArquivo)); att.Loading = true; bool fileExists = fileSystem.FileExists(file); using (var stream = fileSystem.GetFileStream(file)) { if (!fileExists || stream.Length < att.Tamanho) { await HttpRequest.DownloadFileToStream(EndPointHelper.GetAbsoluteUrl(att.Url), stream); stream.Flush(); } } att.Loading = false; ShareViewModel share = new ShareViewModel(); share.FileName = file; share.MimeType = att.MimeType; share.Share(); } catch (Exception ex) { await DisplayAlert(AppResources.APP_TITLE, ex.Message, AppResources.OK); } }
private void ShowPDF() { string pdfFolder = GetPDFDir(this.SignatureRequest); string fileName = fileSystem.JoinPaths(pdfFolder, "document.pdf"); fileSystem.CreateFolder(pdfFolder); using (var stream = fileSystem.GetFileStream(fileName)) { stream.Write(Document.PdfContent, 0, Document.PdfContent.Length); stream.Flush(); } HtmlWebViewSource html = new HtmlWebViewSource(); if (Device.OS != TargetPlatform.iOS) { //Existe um bug no WebView do iOS: https://developer.xamarin.com/guides/xamarin-forms/working-with/webview/ html.BaseUrl = DependencyService.Get <IBaseUrl>().Get(); } string pageSource = String.Format( @"<html> <head> <script type = 'text/javascript'> var url = 'file://{0}'; </script> <script type='text/javascript' src='compatibility.js'></script> </head> <body> <div id='pages'> </div> <script type='text/javascript' src='../build/pdf.js'></script> <script type='text/javascript' src='customview.js'></script> </body> </html>" , fileName); try { if (Device.OS != TargetPlatform.iOS) { html.Html = pageSource; pdfWebView.Source = html; } else { //iOS requires this action on the main UI thread Device.BeginInvokeOnMainThread(() => { html.Html = pageSource; pdfWebView.Source = html; }); } //url.Url = DependencyService.Get<IBaseUrl>().Get() + "index.html"; //?file=" + WebUtility.UrlEncode(fileName.Result); PdfShareViewModel.FileName = fileName; PdfShareViewModel.MimeType = "application/pdf"; pdfLoaded = true; } catch (Exception e) { UserDialogs.Instance.Alert(e.Message, AppResources.APP_TITLE, AppResources.OK); } }