コード例 #1
0
        /// <summary>
        /// 按钮点击事件-上传文件
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">事件参数</param>
        private void OKBtn_Click(object sender, RoutedEventArgs e)
        {
            List< FileUP> files = null;
            long fileTotalLength = 0;
            if (FileNameList.Items.Count > 0)
            {
                files = new List<FileUP>();
                UserListBoxItem userListBoxItem;

                imageFilter = FileFilterUtil.GetImageFilters();
                documentFilter = FileFilterUtil.GetDocumentFilters();

                foreach (object item in FileNameList.Items)
                {
                    userListBoxItem = item as UserListBoxItem;
                    string path = userListBoxItem.Value;

                    if (File.Exists(path))
                    {
                        string fileType = path.Substring(path.LastIndexOf('.'), path.Length - path.LastIndexOf('.'));
                        string fileName = userListBoxItem.Display;

                        Stream stream = File.Open(path, FileMode.Open, FileAccess.Read);
                        byte[] data = new byte[stream.Length];
                        stream.Read(data, 0, data.Length);
                        stream.Seek(0, SeekOrigin.Begin);

                        fileTotalLength += stream.Length;
                         ToolingManWPF.StorageManageServiceReference.AttachmentType attachType =  ToolingManWPF.StorageManageServiceReference.AttachmentType.PICTURE;

                        if (imageFilter.Contains(fileType))
                        {
                            attachType =  ToolingManWPF.StorageManageServiceReference.AttachmentType.PICTURE;
                        }
                        else if (documentFilter.Contains(fileType))
                        {
                            attachType =  ToolingManWPF.StorageManageServiceReference.AttachmentType.DOCUMENT;
                        }
                        files.Add(new ToolingManWPF.StorageManageServiceReference.FileUP() { Name = fileName, FileType = fileType, Type = attachType, Data = data });
                    }
                }

            }

            if (fileTotalLength < long.Parse((new ConfigUtil("MAXFILELENGTH")).Get("MAXLENGTH")))
            {
                StorageManageServiceClient client = new StorageManageServiceClient();
                Message msg = new Message();
               msg= client.FileUpLoad(files,moldNR);

                MessageBox.Show(msg.Content);
            }
            else
                MessageBox.Show("一次上传文件大小不可大于50M", "", MessageBoxButton.OK, MessageBoxImage.Information);
        }
コード例 #2
0
        /// <summary>
        /// 按钮点击事件-上传文件
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">事件参数</param>
        private void OKBtn_Click(object sender, RoutedEventArgs e)
        {
            List <FileUP> files           = null;
            long          fileTotalLength = 0;

            if (FileNameList.Items.Count > 0)
            {
                files = new List <FileUP>();
                UserListBoxItem userListBoxItem;

                imageFilter    = FileFilterUtil.GetImageFilters();
                documentFilter = FileFilterUtil.GetDocumentFilters();


                foreach (object item in FileNameList.Items)
                {
                    userListBoxItem = item as UserListBoxItem;
                    string path = userListBoxItem.Value;

                    if (File.Exists(path))
                    {
                        string fileType = path.Substring(path.LastIndexOf('.'), path.Length - path.LastIndexOf('.'));
                        string fileName = userListBoxItem.Display;

                        Stream stream = File.Open(path, FileMode.Open, FileAccess.Read);
                        byte[] data   = new byte[stream.Length];
                        stream.Read(data, 0, data.Length);
                        stream.Seek(0, SeekOrigin.Begin);

                        fileTotalLength += stream.Length;
                        ToolingManWPF.StorageManageServiceReference.AttachmentType attachType = ToolingManWPF.StorageManageServiceReference.AttachmentType.PICTURE;

                        if (imageFilter.Contains(fileType))
                        {
                            attachType = ToolingManWPF.StorageManageServiceReference.AttachmentType.PICTURE;
                        }
                        else if (documentFilter.Contains(fileType))
                        {
                            attachType = ToolingManWPF.StorageManageServiceReference.AttachmentType.DOCUMENT;
                        }
                        files.Add(new ToolingManWPF.StorageManageServiceReference.FileUP()
                        {
                            Name = fileName, FileType = fileType, Type = attachType, Data = data
                        });
                    }
                }
            }

            if (fileTotalLength < long.Parse((new ConfigUtil("MAXFILELENGTH")).Get("MAXLENGTH")))
            {
                StorageManageServiceClient client = new StorageManageServiceClient();
                Message msg = new Message();
                msg = client.FileUpLoad(files, moldNR);

                MessageBox.Show(msg.Content);
            }
            else
            {
                MessageBox.Show("一次上传文件大小不可大于50M", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }