0

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)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Matt Canty
  • 2,395
  • 5
  • 35
  • 50

2 Answers2

0

Maybe try this:

Path.GetFullPath()

insomnium_
  • 1,800
  • 4
  • 23
  • 39
  • Hi insomnium, sorry for not noticing your answer sooner. I had a go with this with no luck. I really need to ask for the source code as the error message makes no sense, I've seen a lot of paths and this one does not look illegal! I thought perhaps it required only a directory path - but tried that to no avail too. – Matt Canty Mar 22 '12 at 10:08
0

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

Matt Canty
  • 2,395
  • 5
  • 35
  • 50