Search code examples
c#.netfilepathillegal-charactersimapx

imapX illegal characters in path


PLEASE NOTE, I have found a work around which actually works out better for me. That is to use the byte stream and decode rather than save at all. Therefore answers are non-essential but I would still be interested in any comments people have.

Having trouble with illegal characters in path. I have tried many different versions of the same thing, surely it's just a path I need, and I'm fairly sure I know what one looks like! Can someone suggest what I may be doing wrong?

I am using http://hellowebapps.com/products/imapx/

Connection and everything else is okay!

Code:

            foreach (Message m in _imapClient.Folders["Football"].Messages)
            {
                m.Process();
                List<Attachment> attachment = m.Attachments;

                foreach (var a in attachment)
                {
                    a.SaveFile(@"C:\FileDrop\hello.csv");
                    //a.SaveFile(@"C:\FileDrop\");
                }
            }

Stack Trace:

System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path) at System.IO.Path.GetFileName(String path) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at ImapX.Attachment.SaveFile(String downloadLocation)


Solution

  • The only way it seems to get around this is to get the string from the attachment data directly - using Encoding.GetString() with Convert.FromBase64String()

    return _encoding.GetString(Convert.FromBase64String(contentStream));
    

    Then just save the file as normal: MSDN