/// <summary> /// 新建文件夹 /// </summary> /// <param name="token">token凭证</param> /// <param name="parentFolderId">父文件夹id</param> /// <param name="folderName">文件夹名称</param> /// <returns>ResultInt:Result=0成功,ResultValue:文件夹编号</returns> public static ResultInt CreateFolder(string token, int parentFolderId, string folderName) { try { var uploadFileApiProvider = new DocumentApiProvider(); var organizationApiProvider = new OrganizationApiProvider(); ResultEDocUserInfo eDocUserInfo = organizationApiProvider.GetUserInfoByToken(token); ResultInt result = uploadFileApiProvider.CreateFolder( token, parentFolderId, folderName, string.Empty, 0, 0, 0, string.Empty, string.Empty, 1, DateTime.Now, DateTime.Now, eDocUserInfo.UserInfo.UserRealName, eDocUserInfo.UserInfo.UserRealName ); if (result.Result != 0) { throw new Exception("CreateFolder出错,result=" + result.Result); } return(result); } catch (Exception ex) { throw new Exception("CreateFolder出现异常,exMessage=" + ex.Message); } }
/// <summary> /// 获取文件夹id,如果文件夹不存在则新建文件夹并返回文件夹id /// </summary> /// <param name="token">token凭证</param> /// <param name="parentFolderId">父文件夹id</param> /// <param name="folderName">文件夹名称</param> /// <returns>文件夹id</returns> public static int GetFolder(string token, int parentFolderId, string folderName) { try { var documentApiProvider = new DocumentApiProvider(); folderName = folderName.Trim(); ResultBool resultBool = documentApiProvider.ExistsFolder(token, parentFolderId, folderName); if (resultBool.ResultValue) { return(resultBool.Result); } ResultInt resultInt = CreateFolder(token, parentFolderId, folderName); return(resultInt.ResultValue); } catch (Exception ex) { throw new Exception("GetFolder出现异常,exMessage=" + ex.Message); } }
/// <summary> /// 创建文件 /// </summary> /// <param name="token">token凭证</param> /// <param name="targetFolderId">目标文件夹id</param> /// <param name="uploadFileName">文件名称</param> /// <param name="fileByte">文件流</param> /// <returns>文件id</returns> public static int CreateFile(string token, int targetFolderId, string uploadFileName, byte[] fileByte) { //ResultInt:Result=0成功,ResultValue:文件编号 try { uploadFileName = FormatHelper.FormatFileName(uploadFileName); var uploadFileApiProvider = new UploadFileApiProvider(); ResultInt result = uploadFileApiProvider.CreateFile(token, targetFolderId, uploadFileName, fileByte); if (result.Result != 0) { throw new Exception("CreateFile出错,result=" + result.Result); } return(result.ResultValue); } catch (Exception ex) { throw new Exception("CreateFile出现异常,exMessage=" + ex.Message); } }