#region UploadProcess
public void UploadProcess()
{
DateTime m_start = DateTime.Now;
this.textBox_OutMsg.AppendText("Initialize upload\r\n");
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 faild\r\n");
this.textBox_OutMsg.AppendText("Upload faild.\r\n");
return;
}
this.textBox_OutMsg.AppendText("Open file\r\n");
if(this.m_filePath==null||this.m_filePath==string.Empty||!File.Exists(this.m_filePath))
{
this.textBox_OutMsg.AppendText("Open file error\r\n");
this.textBox_OutMsg.AppendText("Upload faild.\r\n");
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 file\r\n");
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()+"https://www.jb51.net/"+m_fileLength.ToString()+"\r\n");
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.\r\n");
m_fs.Close();
this.m_upload.AbandantUpload(this.m_uploadInstance);
return;
}
}
this.textBox_OutMsg.AppendText("File upload finished.\r\n");
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:\WebbWinUpload\WinFormTest\WebbWinUpload.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
您可能感兴趣的文章: