locked
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)), during Picture folder access

    Question

  • I am working on a application in window store app (c#), i had capture a snapshot which is stored in pictures folder. Now while i am using code to send the mail, during attachment of that snapshot(which is placed in pictures folder) i am getting exception, Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)),

     Windows.Storage.StorageFile file =
                               await Windows.Storage.KnownFolders.PicturesLibrary.GetFileAsync(fileName);

                           string attfile = file.Path;
                           Attachment oAttachment = await oMail.AddAttachmentAsync(attfile);

    Please provide solution for that.

    Monday, November 03, 2014 12:34 PM

All replies

  • Hi SachinIndia,

    I will move this case to Building Windows Store apps with C# or VB forum for better response.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 04, 2014 8:18 AM
  • Hi SachinIndia,

    Please check if you have the right to access Pictures Library in Package.appxmanifest.

    If you still have questions, please post more information about your scenario.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, November 04, 2014 9:03 AM
    Moderator
  • Thanks for your answer and your precious time, but i had already checked that checkbox of picture library still i am getting the same exception. So what else could be the reason for the same exception?, please provide me other solution. 
    Tuesday, November 04, 2014 11:07 AM
  • Hi SachinIndia,

    Can you send me a repro project? I will look into it and let you know the result. Use your OneDeive and share a link here.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, November 04, 2014 12:44 PM
    Moderator
  •    

    @Herro Wong

    Following is the code i am using for mail the snapshot:-

    private void SendEmail_Click(object sender, RoutedEventArgs e)

            {                      SaveScreenshot(GuideMap.DirectionsManager.RouteSummaryView, "MapScreenshot.png");                     

            }

      private async void SaveScreenshot(FrameworkElement captureSource, string suggestedName)

            {

                string fileName = suggestedName;

                var saveFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(fileName,Windows.Storage.CreationCollisionOption.ReplaceExisting);         

                if (saveFile != null)

                {

                    using (var fileStream = await saveFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))

                    {

                        //Capture the screenshot and save it to the file stream.

                        await ScreenshotToStreamAsync(captureSource, fileStream);

                        String Result = "";

                        try

                        {

                            SmtpMail oMail = new SmtpMail("TryIt");

                            SmtpClient oSmtp = new SmtpClient();

                            // Set your gmail email address

                            oMail.From = new MailAddress("xxxxxxxxx@gmail.com");

                            // Add recipient email address, please change it to yours

                           // oMail.To.Add(new MailAddress(TextEmail.Text));

                            // Set email subject and email body text

                            oMail.Subject = "";

                            oMail.TextBody = "";

                            Windows.Storage.StorageFile file =

                               await Windows.Storage.KnownFolders.PicturesLibrary.GetFileAsync(fileName);

                           string attfile = file.Path;

                           Attachment oAttachment = await oMail.AddAttachmentAsync(attfile);

    // At this step (during attachment) i am getting exception "Failed to send email with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

                            // Gmail SMTP server

                            SmtpServer oServer = new SmtpServer("smtp.gmail.com");

                            // User and password for ESMTP authentication          

                            oServer.User = "xxxxxx@gmail.com";

                            oServer.Password = "xxxxxxxxxx";

                            // Enable TLS connection on 25 port, please add this line

                            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

                            await oSmtp.SendMailAsync(oServer, oMail);

                            Result = "Email was sent successfully!";

                        }

                        catch (Exception ep)

                        {

                            Result = String.Format("Failed to send email with the following error: {0}", ep.Message);

                        }

                    }

                }

            }


    • Edited by SachinIndia Wednesday, November 05, 2014 5:47 AM
    Tuesday, November 04, 2014 1:20 PM