User19283 postedHi Avinash,
I have implemented this open PDF function, with help of Sasha's blog...
I had the same problem because I've passed a "new NSUrl(myurl)" in place of 'NSUrl.FromFileName(myurl).
Here my code that is working :
first, create your customs classes, overriding QLPreview classes
```
public class PreviewItem : QLPreviewItem
{
public string Title { get; set; }
public NSUrl Url { get; set; }
public override string ItemTitle { get {return Title;} }
public override NSUrl ItemUrl { get { return Url; } }
}
public class PreviewDatasource : QLPreviewControllerDataSource
{
private NSUrl _url;
private string _title;
public PreviewDatasource(NSUrl url, string Title)
{
_url = url;
_title = Title;
}
public override nint PreviewItemCount(QLPreviewController controler)
{
return 1;
}
public override IQLPreviewItem GetPreviewItem(QLPreviewController controler, nint index)
{
return new PreviewItem { Title = _title, Url = _url };
}
}
```
next, call to display the PDF file (in my case, after downloading PDF file in local... code provided) :
BTProgressHUD.ShowContinuousProgress ("Téléchargement en cours...", ProgressHUD.MaskType.Clear);
Uri uri = new Uri (url);
string documentpath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
string localfilename = Path.GetFileName (uri.AbsoluteUri);
string localpath = Path.Combine (documentpath, localfilename);
var webclient = new WebClient ();
webclient.DownloadFileCompleted+= (sender, e) => {
if (e.Error == null)
{
UIApplication.SharedApplication.InvokeOnMainThread (() => {
BTProgressHUD.Dismiss();
BTProgressHUD.ShowSuccessWithStatus("Téléchargement terminé", 1500);
QLPreviewController qlpreview = new QLPreviewController();
qlpreview.DataSource = new PreviewDatasource(NSUrl.FromFilename(localpath), localfilename);
PresentViewController(qlpreview, true, null);
});
} else {
UIApplication.SharedApplication.InvokeOnMainThread (() => {
BTProgressHUD.Dismiss();
BTProgressHUD.ShowErrorWithStatus("Téléchargement échoué", 1500);
});
}
};
webclient.DownloadFileAsync (uri, localpath);
Hope this helps...