locked
How to send email with document attachment RRS feed

  • Question

  • Hello,

    I want to send an email with pdf documment attached from Windows 8 store app. Please let me know better way to achieve this.

    Thanks,

    Parthiv

    Thursday, August 15, 2013 8:55 AM

Answers

  • http://msdn.microsoft.com/en-us/library/windows/apps/hh871371.aspx

    Sample:

    public sealed partial class MainPage : Page
        {
            private DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    
            public MainPage()
            {
                this.InitializeComponent();
                dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.ShareItemHandler);
            }
    
            private async void ShareItemHandler(DataTransferManager sender, DataRequestedEventArgs args)
            {
                DataRequest request = args.Request;
                request.Data.Properties.Title = "Share pdf or other storage file";
                request.Data.Properties.Description = "How to send file";
    
                DataRequestDeferral deferral = request.GetDeferral();
                try
                {
                    var file = await this.GetPackagedFile("Assets", "pdfsample.pdf");//just get file from Assets/ folder
                    var filesList = new List<StorageFile> { file };
                    request.Data.SetStorageItems(filesList);
                }
                catch (Exception e) 
                {
    
                }
                finally
                {
                    deferral.Complete();
                }   
            }
    
            private async Task<StorageFile> GetPackagedFile(string folderName, string fileName)
            {
                var installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                StorageFile resultFile = null;
    
                if (!string.IsNullOrEmpty(folderName))
                {
                    StorageFolder subFolder = await installFolder.GetFolderAsync(folderName);
                    resultFile = await subFolder.GetFileAsync(fileName);
                }
                else
                {
                    resultFile = await installFolder.GetFileAsync(fileName);
                }
    
                return resultFile;
            } 
        }



    Thursday, August 15, 2013 9:41 AM