| IntegrationFileClientUploadFileAsync 方法 (Bitmap, String, String, String, String, String, String, ActionInt64, Int64) | 
 
            上传内存图片到服务器操作
            
 
        命名空间: 
     HslCommunication.Enthernet
        程序集:
     HslCommunication (在 HslCommunication.dll 中) 版本:12.5.1.0 (12.5.1.0)
 语法
语法public Task<OperateResult> UploadFileAsync(
	Bitmap bitmap,
	string serverName,
	string factory,
	string group,
	string id,
	string fileTag,
	string fileUpload,
	Action<long, long> processReport
)
Public Function UploadFileAsync ( 
	bitmap As Bitmap,
	serverName As String,
	factory As String,
	group As String,
	id As String,
	fileTag As String,
	fileUpload As String,
	processReport As Action(Of Long, Long)
) As Task(Of OperateResult)
public:
Task<OperateResult^>^ UploadFileAsync(
	Bitmap^ bitmap, 
	String^ serverName, 
	String^ factory, 
	String^ group, 
	String^ id, 
	String^ fileTag, 
	String^ fileUpload, 
	Action<long long, long long>^ processReport
)
member UploadFileAsync : 
        bitmap : Bitmap * 
        serverName : string * 
        factory : string * 
        group : string * 
        id : string * 
        fileTag : string * 
        fileUpload : string * 
        processReport : Action<int64, int64> -> Task<OperateResult> 
参数
- bitmap
- 类型:System.DrawingBitmap
 内存图片,不能为空
- serverName
- 类型:SystemString
 服务器存储的文件名称,带后缀
- factory
- 类型:SystemString
 第一大类
- group
- 类型:SystemString
 第二大类
- id
- 类型:SystemString
 第三大类
- fileTag
- 类型:SystemString
 文件的额外描述
- fileUpload
- 类型:SystemString
 文件的上传人
- processReport
- 类型:SystemActionInt64, Int64
 上传的进度报告
返回值
类型:
TaskOperateResult是否成功的结果对象
 异常
异常| 异常 | 条件 | 
|---|
| ArgumentNullException |  | 
 备注
备注
            用于分类的参数
factory,
group,
id中间不需要的可以为空,对应的是服务器上的路径系统。
            
|  警告: | 
|---|
| 失败的原因大多数来自于网络的接收异常,或是客户端不存在文件。 | 
 示例
示例
private void button2_Click( object sender, EventArgs e )
{
    
    using (OpenFileDialog ofd = new OpenFileDialog( ))
    {
        if (ofd.ShowDialog( ) == DialogResult.OK)
        {
            textBox3.Text = ofd.FileName;
        }
    }
}
private async void button3_Click( object sender, EventArgs e )
{
    
    if (!string.IsNullOrEmpty( textBox3.Text ))
    {
        if(!System.IO.File.Exists( textBox3.Text ))
        {
            DemoUtils.ShowMessage( "选择的文件不存在,退出!" );
            return;
        }
        
        
        
        
        
        
        button3.Enabled = false;
        string fileName = textBox3.Text;
        System.IO.FileInfo fileInfo = new System.IO.FileInfo( fileName );
        DateTime uploadStartTime = DateTime.Now;
        
        
        OperateResult result = await integrationFileClient.UploadFileAsync(
            fileName,                       
            fileInfo.Name,                  
            textBox_upload_factory.Text,    
            textBox_upload_group.Text,      
            textBox_upload_id.Text,         
            textBox_upload_tag.Text,        
            textBox_upload_name.Text,       
            UpdateReportProgress            
            );
        button3.Enabled = true;
        if (result.IsSuccess)
        {
            
            DemoUtils.ShowMessage( "文件上传成功!耗时:" + (DateTime.Now - uploadStartTime).TotalSeconds.ToString( "F1" ) + " 秒" );
        }
        else
        {
            
            
            DemoUtils.ShowMessage( "文件上传失败:" + result.ToMessageShowString( ) );
        }
    }
    else
    {
        DemoUtils.ShowMessage( "Please Select a File" );
    }
}
private void ThreadUploadFile( object filename )
{
    if (filename is string fileName)
    {
        System.IO.FileInfo fileInfo = new System.IO.FileInfo( fileName );
        
        
        OperateResult result = integrationFileClient.UploadFile(
            fileName,                       
            fileInfo.Name,                  
            textBox_upload_factory.Text,    
            textBox_upload_group.Text,      
            textBox_upload_id.Text,         
            textBox_upload_tag.Text,        
            textBox_upload_name.Text,       
            UpdateReportProgress            
            );
        
        
        Invoke( new Action<OperateResult>( operateResult =>
        {
            button3.Enabled = true;
            if (result.IsSuccess)
            {
                
                DemoUtils.ShowMessage( "文件上传成功!" );
            }
            else
            {
                
                
                DemoUtils.ShowMessage( "文件上传失败:" + result.ToMessageShowString( ) );
            }
        } ), result );
    }
}
private void UpdateReportProgress( long sended, long totle )
{
    if (progressBar1.InvokeRequired)
    {
        progressBar1.Invoke( new Action<long, long>( UpdateReportProgress ), sended, totle );
        return;
    }
    
    
    int value = (int)(sended * 100L / totle);
    label10.Text = sended + "/" + totle;
    progressBar1.Value = value;
} 参见
参见