コード例 #1
0
ファイル: DevContract.cs プロジェクト: hmxiaoxiao/haimenlg
        private void tsbAttachNew_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog() { Title = "请选择需要上传的文件",
                                                       ValidateNames = true,
                                                       CheckFileExists = true,
                                                       CheckPathExists = true };

            if (fd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                FileInfo fi = new FileInfo(fd.FileName);
                // 先保存到数据库里
                Attach att = new Attach() { FileName = fi.Name, FileType = fi.Extension };
                att.Save();

                FTPClient ftp = INICustomer.GetFTPClient();
                ftp.fileUpload(fi, @"\", att.ID + fi.Extension);

                m_contract.AttachList.Add(att);

                // 加入列表
                lstFiles.Items.Add(String.Format("{0}.{1}", att.ID, fi.Name), 2);
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            acct = Session[Constants.sessionAccount] as Account;
            if (acct == null)
            {
                Response.Redirect("default.aspx", true);
            }
            else
            {
                if (acct.UserOfAccount.Settings.RTL)
                {
                    _stylesRtl = true;
                }
                defaultSkin = Utils.EncodeJsSaveString(acct.UserOfAccount.Settings.DefaultSkin);
                _manager    = (new WebmailResourceManagerCreator()).CreateResourceManager();

                if (Request.QueryString["filename"] != null)
                {
                    FileName = Request.QueryString["filename"];
                }

                try
                {
                    IsHTMLMsg = false;
                    msgPlain  = null;
                    msgHTML   = null;

                    string tempFolder = Utils.GetTempFolderName(Page.Session);
                    string FilePath   = Path.Combine(tempFolder, FileName);

                    msg.Parser.WorkingFolder = tempFolder;
                    msg.LoadMessage(FilePath);

                    LabelFrom.Text = Server.HtmlEncode(msg.From.ToString());
                    LabelTo.Text   = Server.HtmlEncode(msg.To.ToString());
                    CcAddr         = msg.Cc.ToString();
                    if (CcAddr != string.Empty)
                    {
                        LabelCc.Text = Server.HtmlEncode(msg.Cc.ToString());
                    }
                    DateFormatting df = new DateFormatting(acct, msg.Date);
                    LabelDate.Text    = df.FullDate;
                    LabelSubject.Text = Server.HtmlEncode(msg.Subject);

                    AttachmentCollection AttachmentsColl = msg.Attachments;

                    StringBuilder sb = new StringBuilder();
                    foreach (Attachment Attach in AttachmentsColl)
                    {
                        string filename = Utils.CreateTempFilePath(tempFolder,
                                                                   (Attach.Filename.Length > 0) ? Attach.Filename : Attach.Name);
                        Attach.Save(filename, true);

                        FileInfo fi = new FileInfo(filename);

                        if (Attach.ContentType.ToLower().StartsWith("image"))
                        {
                            sb.AppendFormat(@"<a href=""{1}"">{0}</a>", Attach.Filename, Utils.GetAttachmentDownloadLink(Attach, false));
                            sb.AppendFormat(@" (<a href=""{0}"">View</a>), ", Utils.GetAttachmentDownloadLink(Attach, true));
                        }
                        else if (Attach.ContentType.ToLower().StartsWith("message"))
                        {
                            sb.AppendFormat(@"<a href=""{1}"">{0}</a>", Attach.Filename, Utils.GetAttachmentDownloadLink(Attach, false));
                            sb.AppendFormat(@" (<a href=""view-embedded-msg.aspx?filename={0}"">View</a>), ", fi.Name);
                        }
                        else
                        {
                            sb.AppendFormat(@"<a href=""{1}"">{0}</a>, ", Attach.Filename, Utils.GetAttachmentDownloadLink(Attach, false));
                        }
                    }
                    if (sb.Length > 2)
                    {
                        sb.Remove(sb.Length - 2, 2);
                    }
                    Attachments = sb.ToString();
                    if (Attachments.Length > 0)
                    {
                        LabelAttachments.Text = Attachments;
                    }

                    msgPlain = Utils.MakeHtmlBodyFromPlainBody(msg.BodyPlainText, true, "");
                    msgHTML  = msg.BodyHtmlText;
                    if (msgPlain == "")
                    {
                        msgPlain = Utils.ConvertHtmlToPlain(msgHTML);
                    }
                    if (msgHTML != "")
                    {
                        IsHTMLMsg = true;
                        //Message body
                        MessageBody.Text = msgHTML;
                    }
                    else
                    {
                        IsHTMLMsg        = false;
                        MessageBody.Text = msgPlain;
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteException(ex);
                }
            }
        }