/// <summary> /// 下载文件 /// </summary> /// <param name="fileName"></param> public void ucBook_DownLoadFile(string uri) { try { //存储文件对话框 SaveFileDialog saveFileDialog = new SaveFileDialog(); //保存对话框是否记忆上次打开的目录 saveFileDialog.RestoreDirectory = true; //设置默认文件名(可以不设置) saveFileDialog.FileName = System.IO.Path.GetFileName(uri); if (saveFileDialog.ShowDialog() == true) { //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); webClientManage.FileDown(uri, saveFileDialog.FileName, SpaceCodeEnterEntity.LoginUserName, SpaceCodeEnterEntity.WebLoginPassword, SpaceCodeEnterEntity.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { })); } //webClientManage.FileDown(fileName) } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } }
/// <summary> /// 打开图片文件 /// </summary> /// <param name="uri"></param> public void OpenPictureFile(string uri) { try { //获取文件名称(包含扩展名称) var fileName = System.IO.Path.GetFileName(uri); //本地地址 var loaclF = Constant.LocalTempRoot + "\\" + fileName; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); //文件下载 webClientManage.FileDown(uri, loaclF, Constant.LoginUserName, Constant.WebLoginPassword, Constant.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { try { if (IsSuccessed) { if (File.Exists(loaclF)) { wordManage.ClearDocuments(); pPTManage.ClearDocuments(); excelManage.ClearDocuments(); this.Dispatcher.BeginInvoke(new Action(() => { try { if (this.pictureView == null) { this.pictureView = new PictureView(loaclF); } else { this.pictureView.OpenUri(loaclF); } //加载UI事件(比如多媒体播放器,浏览器) this.book_LoadUI(this.pictureView); } catch (Exception ex2) { LogManage.WriteLog(this.GetType(), ex2); }; })); } } } catch (Exception ex2) { LogManage.WriteLog(this.GetType(), ex2); } })); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } }
/// <summary> /// 打开record文件 /// </summary> /// <param name="uri"></param> public void OpenRecordFile(string uri) { try { //获取文件名称(包含扩展名称) var fileName = System.IO.Path.GetFileName(uri); //本地地址 var loaclF = this.LocalTempRoot + "\\" + fileName; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); //文件下载 webClientManage.FileDown(uri, loaclF, this.LoginUserName, this.WebLoginPassword, this.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { if (IsSuccessed) { try { if (File.Exists(loaclF)) { //通过流去获取文件字符串 using (FileStream fs = new FileStream(loaclF, FileMode.Open, FileAccess.Read)) { StreamReader reader = new StreamReader(fs, Encoding.UTF8); string recordUri = reader.ReadToEnd(); Application.Current.Dispatcher.BeginInvoke(new Action(() => { try { //打开视频文件 this.OpenVideoAudioFile(recordUri); } catch (Exception ex2) { LogManage.WriteLog(this.GetType(), ex2); }; })); } } } catch (Exception ex2) { LogManage.WriteLog(this.GetType(), ex2); } } })); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } }
/// <summary> /// 实时共享 /// </summary> /// <param name="uri"></param> /// <param name="fileType"></param> void ucBook_RealShareFile(string uri, fileType fileType) { try { if (ShareInConversationSelfNavicateCallBack != null) { this.ShareInConversationSelfNavicateCallBack(new Action <bool>((canSharing) => { if (canSharing) { //获取文件名称(包含扩展名称) var fileName = System.IO.Path.GetFileName(uri); ////获取文件名称(不包含扩展名称) //var fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(uri); //if (fileType == fileType.one) //{ // fileNameWithoutExtension = this.OneNoteFuzzy; //} //本地地址 var loaclF = SpaceCodeEnterEntity.LocalTempRoot + "\\" + fileName; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); webClientManage.FileDown(uri, loaclF, SpaceCodeEnterEntity.LoginUserName, SpaceCodeEnterEntity.WebLoginPassword, SpaceCodeEnterEntity.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { if (IsSuccessed) { if (this.FileShareCallBack != null) { this.FileShareCallBack(loaclF, fileType); } } })); } else { MessageBox.Show("共享之前请先选择一个会话", "操作提示", MessageBoxButton.OK, MessageBoxImage.Information); } })); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } }
/// <summary> /// 下载附件 /// </summary> /// <param name="list"></param> /// <param name="contentType"></param> private void FileDownLoad(spClient.List list, string contentType) { bool result = client.LoadMethod(list.RootFolder); if (!result) { return; } client.LoadMethod(list.RootFolder.Folders); foreach (var ccp in list.RootFolder.Folders) { client.LoadMethod(ccp); if (ccp.Name.Equals("Attachments")) { rootDic.Clear(); client.LoadMethod(ccp.Folders); foreach (var itemChild in ccp.Folders) { var t = itemChild.Name; client.LoadMethod(itemChild.Files); string files = null; foreach (var file in itemChild.Files) { client.LoadMethod(file); Thread.Sleep(100); WebClientManage webClient = new WebClientManage(); webClient.FileDown(beforeImageSite + file.ServerRelativeUrl, Environment.CurrentDirectory + "\\" + contentType + "\\" + System.IO.Path.GetFileName(file.ServerRelativeUrl), userName, password, domain, new Action <int>((r) => { }), new Action <Exception, bool>((errir, isSuccessed) => { })); files += file.ServerRelativeUrl + ","; } if (!string.IsNullOrEmpty(files)) { rootDic.Add(Convert.ToInt32(t), files); } } break; } } }
/// <summary> /// 文件共享 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnFileShare_Click(object sender, RoutedEventArgs e) { try { string fileName = IOOperation.GetFileName(TreeCodeEnterEntity.currentFileUri); //本地地址 var loaclF = TreeCodeEnterEntity.LocalTempRoot + "\\" + fileName; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); webClientManage.FileDown(TreeCodeEnterEntity.currentFileUri, loaclF, TreeCodeEnterEntity.LoginUserName, TreeCodeEnterEntity.WebLoginPassword, TreeCodeEnterEntity.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { if (IsSuccessed) { if (ConferenceTreeView.conferenceTreeView.FileShareCallBack != null) { ConferenceTreeView.conferenceTreeView.FileShareCallBack(loaclF, TreeCodeEnterEntity.currentFileType); } //if (TreeCodeEnterEntity.currentFileType == wpfHelperFileType.pptx || TreeCodeEnterEntity.currentFileType == wpfHelperFileType.ppt) //{ // if (ConferenceTreeView.conferenceTreeView.PPtShareCallBack != null) // { // ConferenceTreeView.conferenceTreeView.PPtShareCallBack(loaclF); // } //} //else //{ // if (ConferenceTreeView.conferenceTreeView.CommonFileShareCallBack != null) // { // ConferenceTreeView.conferenceTreeView.CommonFileShareCallBack(loaclF); // } //} } })); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
void OpenFileByLocalApp(string uri) { try { //获取文件名称(包含扩展名称) var fileName = System.IO.Path.GetFileName(uri); //本地地址 var loaclF = this.LocalTempRoot + "\\" + fileName; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); //PictureView pictureView = new PictureView(); //pictureView.Title = Path.GetFileNameWithoutExtension(uri); ////加载UI事件(比如多媒体播放器,浏览器) //this.book_LoadUI(pictureView); //文件下载 webClientManage.FileDown(uri, loaclF, this.LoginUserName, this.WebLoginPassword, this.UserDomain, new Action <int>((intProcess) => { }), new Action <Exception, bool>((ex, IsSuccessed) => { try { if (IsSuccessed) { if (File.Exists(loaclF)) { ProcessManage.OpenFileByLocalAddress(loaclF); } } } catch (Exception ex2) { LogManage.WriteLog(this.GetType(), ex2); } })); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
//private int BeginSingle(Action callback, spClient.List list, cm cm, List<Dictionary<string, object>> diclist, int count, Dictionary<string, object> item) //{ // return count; //} #region 图片下载 private string ImageDownload(string html, string contentType, string[] imgUrils, Action callback) { int imgDownload_count = 0; if (checkBoxNeedDownloadImage.IsChecked == true) { for (int i = 0; i < imgUrils.Count(); i++) { if (html.Contains(imgUrils[i])) { html = html.Replace(imgUrils[i], beforeImageSite + imgUrils[i].Replace("%", "_")); } Thread.Sleep(imageDownloadSpeed); string imguri = System.IO.Path.GetFileName(imgUrils[i]); imguri = imguri.Replace("%", "_"); WebClientManage webClient = new WebClientManage(); if (imguri == "20169129358470.jpg" || imguri == "201691293451187.jpg" || imguri == "2016913112928749.jpg") { } webClient.FileDown(beforeImageSite + imgUrils[i], Environment.CurrentDirectory + "\\" + contentType + "\\" + imguri, userName, password, domain, new Action <int>((r) => { }), new Action <Exception, bool>((errir, isSuccessed) => { imgDownload_count++; if (isSuccessed && imgDownload_count == imgUrils.Count()) { callback(); } })); } if (imgUrils.Count() == 0) { callback(); } } else { callback(); } return(html); }
/// <summary> /// 下载 /// </summary> /// <param name="downLoadProgress">下载进度</param> protected void DownLoad_File(ProgressBar downLoadProgress) { try { if (!string.IsNullOrEmpty(TreeCodeEnterEntity.currentFileUri)) { //打开文件存储对话框 FileManage.OpenDialogThenDoing(TreeCodeEnterEntity.currentFileUri, new Action <string>((fileName) => { downLoadProgress.Value = 0; downLoadProgress.Visibility = vy.Visible; //创建一个下载管理实例 WebClientManage webClientManage = new WebClientManage(); webClientManage.FileDown(TreeCodeEnterEntity.currentFileUri, fileName, TreeCodeEnterEntity.LoginUserName, TreeCodeEnterEntity.WebLoginPassword, TreeCodeEnterEntity.UserDomain, new Action <int>((intProcess) => { this.Dispatcher.BeginInvoke(new Action(() => { //设置进度 downLoadProgress.Value = intProcess; })); }), new Action <Exception, bool>((ex, IsSuccessed) => { this.Dispatcher.BeginInvoke(new Action(() => { //设置进度 downLoadProgress.Value = downLoadProgress.Maximum; downLoadProgress.Visibility = vy.Collapsed; })); })); })); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }