收邮件时获取附件的问题

我在windows窗体中做了一个获取邮件附件的方法,下面是代码,但是问什么没有成功啊

string path = "";
                        //获取附件
                        foreach (MimeEntity entry in m.Attachments)
                        {
                            string fileName = entry.ContentDisposition_FileName; //获取文件名称
                            path = "E:\\jmail\\WindowsFormsApplication1\\Attch\\" + fileName;
                            if (File.Exists(path))
                            {
                                Random random = new Random();
                                int newfile = random.Next(1, 100000);
                                path = "E:\\jmail\\WindowsFormsApplication1\\Attch\\Attch" + newfile.ToString();
                                Directory.CreateDirectory(path);
                                path += "\\" + fileName;
                            }
                            byte[] data = entry.Data;
                            FileStream pFileStream = null;
                            pFileStream = new FileStream(path, FileMode.Create);
                            pFileStream.Write(data, 0, data.Length);
                            pFileStream.Close();
                        }

富国沪深
浏览 372回答 4
4回答

慕丝7291255

调试一下出什么异常呢?

慕森卡

检查一下路径
打开App,查看更多内容
随时随地看视频慕课网APP