Cannot convert from 'string' to Windows.Storage.StorageFile RRS feed

  • Question

  • Hi Everyone

    I'm having difficulties with referring to a path in C#.
    I would like to automate the process of getting a file from a directory in the network, store it locally.
    When the system comes online I want to zip all the files that have been stored locally and send them to an email adress using the smtp setting of outlook.

    I want to test this by creating a mail, download one file through ftp and send it immediatly.
    But with referring to the path to the attachment, the problem ocurs.

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Diagnostics.CodeAnalysis;
    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 System.ComponentModel; 
    using System.Data;
    using System.Text; 
    using System.Threading.Tasks;
    using Limilabs.Mail;
    using Fluent = Limilabs.Mail.Fluent;
    using Limilabs.Mail.Headers;
    using Limilabs.Client.SMTP;
    using Limilabs.Mail.MIME;
    using FluentFTP;
    using System.Net;
    //I do not need everything, I know
    // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
    namespace CMBmailingC
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
            public MainPage()
            private void btnSend_Click(object sender, RoutedEventArgs e)
                // Use builder class to create new email message
                MailBuilder builder = new MailBuilder();
                builder.From.Add(new MailBox("mail@mail.com", "Name1"));
                builder.To.Add(new MailBox("othermail@mail.com", "Name2"));
                builder.Subject = "Test";
                builder.Text = "This is plain text message.";
                // Read attachment from disk, add it to Attachments collection
                FtpClient client = new FtpClient(@"\\ThePathThatIsShownInExplorer");
                client.Credentials = new NetworkCredential("admin", "admin");
                if (client.FileExists(@"\\ThePathThatIsShownInExplorer\180415_005223_PIM_7654321_00000006.xml"))
                    client.DownloadFile(@"C:\locallyStorage", @"\\ThePathThatIsShownInExplorer\180415_005223_PIM_7654321_00000006.xml", true);
                    MimeData attachment = builder.AddAttachment(@"C:\locallyStorage\180415_005223_PIM_7654321_00000006.xml");
                    IMail email = builder.Create();
                    // Send the message
                    using (Smtp smtp = new Smtp())
                        smtp.Connect("smtp-mail.outlook.com");   // or ConnectSSL for SSL You can use Connect(string host, int port) overload when you need to specify different port (for example 25). 
                        smtp.UseBestLoginAsync("user", "password");

    Does anyone know how to solve this?
    Working with the latest VisualStudios 2017 Community, I have been looking online for hours, tried a lot and failed equally as much.

    I think I'm overlooking something really easy, because there are many examples where everything works.

     // Read attachment from disk, add it to Attachments collection
            MimeData attachment = builder.AddAttachment(@"../image.jpg");
    Example from ; https://www.limilabs.com/blog/send-email-with-attachment

    I thank you already for your time for looking at this question!



    Monday, September 3, 2018 2:24 PM

All replies

  • Hi,

    Well, it seems that you are using a third party library to send the email. It is out of the scope of UWP forum.

    The problem seems to be related to the file access permissions. You could not directly access file unless it's in Application install directory,Application data locations or some libraries that needs capabilities. You could get more information here:File access permissions and Skip the path: stick to the StorageFile

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 4, 2018 9:33 AM