/// <summary> /// 上传文件控件 /// </summary> /// <param name="fileFullPath">上传的文件全路径</param> /// <param name="saveURL">需要上传到Ftp目录URL</param> public FileUploadControl(string fileFullPath, string saveURL) { InitializeComponent(); this.lblSpeed.Text = "正在传输..."; this.fileFullPath = fileFullPath; this.fileName = fileFullPath.Substring(fileFullPath.LastIndexOf("\\") + 1); this.ftpURL = saveURL.EndsWith("/")? saveURL + fileName : saveURL + "/" + fileName; this.pictureBox1.Image = Common.GetFileIcon(fileFullPath).ToBitmap(); FileInfo fileInfo = new FileInfo(this.fileFullPath); fileSize = fileInfo.Length; progressBar1.Maximum = (int)fileSize; ftpUpload = new FtpUpload(this.fileFullPath, ftpURL); ftpUpload.FileUploadProgress += new EventHandler<FileUploadProgressEventArgs>(ftpUpload_FileUploadProgress); ftpUpload.Start(); }
public void sendImage(Bitmap bitmap) { try { string fileName = createImageName() + ".jpg"; string imageFilePath = Application.StartupPath.ToString() + "/" + chat.ChatId + "/" + fileName; bitmap.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); FtpUpload ftpUpload = new FtpUpload(imageFilePath, uploadURL + "/" + fileName); operatorServiceAgent.SendFile(fileName, chat.ChatId, "start"); string msg = string.Format("<span style=\"font-family: Arial;color:blue;font-weight: bold;font-size: 12px;\">{0} :</span><br/><span style=\"font-family: Arial;font-size: 12px;\"><img src='{1}' /></span><br />", operatorServiceAgent.CurrentOperator.NickName + " " + DateTime.Now.ToString("hh:mm:ss"), imageFilePath); chatMessageViewerControl1.AddText(msg); uploadTasks.Add(ftpUpload); ftpUpload.FileUploadProgress += new EventHandler<FileUploadProgressEventArgs>(ftpUpload_FileUploadProgress); ftpUpload.Start(); } catch (ExternalException eex) { Trace.WriteLine("sendImage ExternalException:" + eex.Message); chatMessageViewerControl1.AddInformation("网络出现问题,暂时无法获取及发送消息"); return; } catch (Exception ex) { Trace.WriteLine("sendImage exception:" + ex.Message); chatMessageViewerControl1.AddInformation("网络出现问题,暂时无法获取及发送消息"); return; } }