Thanx for your support, the sample u provided is working great!! but when i modified it in a way that user can save the resultant file, i am getting ACESS DENIED error, i used a folder in my pc as sd card for windows phone emulator, here is the code part that i have changed
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Windows.Storage.Pickers;
using Windows.Storage;
using Windows.Storage.Provider;
using System.Reflection;
using Syncfusion.Pdf.Interactive;
using Windows.UI.Popups;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.Activation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace WinPhoneApp
{
public sealed partial class MainPage : Page
{
CoreApplicationView view;
CoreApplicationView sview;
string filePath = string.Empty;
MemoryStream ms = new MemoryStream();
public MainPage()
{
this.InitializeComponent();
view = CoreApplication.GetCurrentView();
sview = CoreApplication.GetCurrentView();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
filePath = string.Empty;
FileOpenPicker filePicker = new FileOpenPicker();
filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
filePicker.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
filePicker.FileTypeFilter.Clear();
filePicker.FileTypeFilter.Add(".pdf");
filePicker.PickSingleFileAndContinue();
view.Activated += viewActivated;
}
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
{
FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
if (args != null)
{
if (args.Files.Count == 0) return;
view.Activated -= viewActivated;
StorageFile storageFile = args.Files[0];
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
Stream docStream = stream.AsStreamForRead();
//loaded the Pdf file
PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream);
//Creating a new PDF document
PdfDocument doc = new PdfDocument();
doc.ImportPageRange(ldoc, 0, 1);
doc.Save(ms);
//trying to save file to user stated location
var savepicker = new FileSavePicker();
savepicker.FileTypeChoices.Add("Pdf", new List<string>() { ".pdf" });
savepicker.SuggestedFileName = "Result";
savepicker.PickSaveFileAndContinue();
sview.Activated += sviewActivated;
//Close the PDF document
doc.Close(true);
ldoc.Close(true);
}
}
private async void sviewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
{
FileSavePickerContinuationEventArgs args = args1 as FileSavePickerContinuationEventArgs;
ms.Position = 0;
if (args != null)
{
sview.Activated -= sviewActivated;
StorageFile stFile = args.File;
if (stFile != null)
{
Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite);
Stream st = fileStream.AsStreamForWrite();
st.SetLength(0);
st.Write((ms as MemoryStream).ToArray(), 0, (int)ms.Length);
st.Flush();
st.Dispose();
fileStream.Dispose();
}
MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully.");
UICommand yesCmd = new UICommand("Yes");
msgDialog.Commands.Add(yesCmd);
UICommand noCmd = new UICommand("No");
msgDialog.Commands.Add(noCmd);
IUICommand cmd = await msgDialog.ShowAsync();
if (cmd == yesCmd)
{
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(stFile);
}
}
}
}
}