#region UploadProcess public void UploadProcess() { DateTime m_start = DateTime.Now; this.textBox_OutMsg.AppendText("Initialize uploadrn"); if(this.m_upload==null||this.m_uploadGUID==null||this.m_uploadGUID==string.Empty) { this.textBox_OutMsg.AppendText("Upload instance id error or login to the server faildrn"); this.textBox_OutMsg.AppendText("Upload faild.rn"); return; } this.textBox_OutMsg.AppendText("Open filern"); if(this.m_filePath==null||this.m_filePath==string.Empty||!File.Exists(this.m_filePath)) { this.textBox_OutMsg.AppendText("Open file errorrn"); this.textBox_OutMsg.AppendText("Upload faild.rn"); return; } FileInfo m_fileInfo = new FileInfo(this.m_filePath); FileStream m_fs = new FileStream(this.m_filePath, FileMode.Open, FileAccess.Read); this.textBox_OutMsg.AppendText("Start upload filern"); int m_buffer = 10; //KBytes long m_currentPoint = 0; long m_fileLength = m_fileInfo.Length; bool m_uploadResult = false; byte[] m_data = new byte[m_buffer*1024]; long m_readBytes = m_fs.Read(m_data, 0, m_buffer*1024); this.UploadProcessBar.Maximum = 100; this.UploadProcessBar.Minimum = 0; while(m_readBytes>0) { MemoryStream m_memoryStream = new MemoryStream(m_data, 0,(int)m_readBytes); DimeAttachment dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, m_memoryStream); this.m_upload.RequestSoapContext.Attachments.Add(dimeAttach); m_uploadResult = this.m_upload.UploadFileData(this.m_uploadInstance,m_currentPoint,m_readBytes); if(m_uploadResult) { m_currentPoint +=m_readBytes; m_readBytes = m_fs.Read(m_data,0,m_buffer*1024); // this.textBox_OutMsg.AppendText("Uploading:"+m_currentPoint.ToString()+"http://www.jb51.net/"+m_fileLength.ToString()+"rn"); this.UploadProcessBar.Value = (int)(m_currentPoint*100/m_fileLength); this.label_outPercent.Text = this.UploadProcessBar.Value.ToString()+"%"; } else { this.textBox_OutMsg.AppendText("Upload file error.rn"); m_fs.Close(); this.m_upload.AbandantUpload(this.m_uploadInstance); return; } } this.textBox_OutMsg.AppendText("File upload finished.rn"); this.button_Cancel.Enabled = false; m_fs.Close(); this.ResetForm(); } #endregion
测试项目代码: 客户上传/webbwinupload.zip
出现错误的解决方法: *****************************************************
引用内容 Error 1 'WinFormTest.localhost.WebbWinUpload' does not contain a definition for 'RequestSoapContext' D:WebbWinUploadWinFormTestWebbWinUpload.cs 448 19 WinFormTest
当你更新Web引用的时候,.net自动生成的Web引用为: public class WebbWinUpload : System.Web.Services.Protocols.SoapHttpClientProtocol 请转化为: public class WebbWinUpload : Microsoft.Web.Services2.WebServicesClientProtocol 查找引用下自动生成的C#文件Reference.cs
(编辑:焦作站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|