public static void Move(ArtifactDetails artifactDetails, string destination) { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } if (!string.IsNullOrEmpty(artifactDetails.ContentPackageFilePath)) { DeleteDestinationFileIfExsistsAlready(artifactDetails.ContentPackageFilePath, destination); File.Move(artifactDetails.ContentPackageFilePath, String.Concat(destination, "\\", artifactDetails.ContentPackageFilePath)); } if (!string.IsNullOrEmpty(artifactDetails.ItemsToPublishFilePath)) { DeleteDestinationFileIfExsistsAlready(artifactDetails.ItemsToPublishFilePath, destination); File.Move(artifactDetails.ItemsToPublishFilePath, String.Concat(destination, "\\", artifactDetails.ItemsToPublishFilePath)); } if (!string.IsNullOrEmpty(artifactDetails.ReleaseNotesFilePath)) { DeleteDestinationFileIfExsistsAlready(artifactDetails.ReleaseNotesFilePath, destination); File.Move(artifactDetails.ReleaseNotesFilePath, String.Concat(destination, "\\", artifactDetails.ReleaseNotesFilePath)); } }
public ArtifactDetails CreateArtifacts(string sourcePath, string targetPath) { var commands = _sitecoreSerializationDiffGenerator.GetDiffCommands(sourcePath, targetPath); var diff = new DiffInfo(commands, "Sitecore Courier Package", string.Empty, string.Format("Diff between folders '{0}' and '{1}'", sourcePath, targetPath)); Update.Engine.PackageGenerator.GeneratePackage(diff, string.Empty, PACKAGE_NAME); CreateItemsToPublishFile(commands); var artifactDetails = new ArtifactDetails { ContentPackageFilePath = PACKAGE_NAME, ItemsToPublishFilePath = ITEM_TO_PUBLISH_FILE }; return(artifactDetails); }
private WordServiceResponse SubmitFile(WordServiceRequestNew request) { WordServiceResponse response = new WordServiceResponse(); var fileData = System.Convert.FromBase64String(request.Content); MemoryStream ms = new MemoryStream(fileData); //FileStream file = new FileStream("C:\\DEV3\\Attachments\\" + request.attachments[0].name, FileMode.Create, FileAccess.Write); //ms.WriteTo(file); //file.Close(); //ms.Close(); //string messsage = ""; try { string siteUrl = "https://nylonline.sharepoint.com/sites/ibm"; using (ClientContext spContext = new ClientContext(siteUrl)) { //messsage += "CP1 <br />"; Web spWeb = spContext.Web; spContext.Credentials = new SharePointOnlineCredentials("*****@*****.**", GetSecureString("kmp@2017")); spContext.Load(spWeb); spContext.ExecuteQuery(); //messsage += "CP2 <br />"; string title = spWeb.Title; //messsage += "CP3 <br />"; //messsage += "CP4 " + title + " <br />"; var targetFileUrl = String.Format("{0}/{1}", "/IT Business Management Documents", request.Name); ms.Position = 0; //messsage += "CP5 <br />"; var list = spContext.Web.Lists.GetByTitle("IT Business Management Documents"); spContext.Load(list.RootFolder); spContext.ExecuteQuery(); //messsage += "CP6 <br />"; var fileUrl = Path.Combine(list.RootFolder.ServerRelativeUrl, request.Name); //messsage += "CP7 <br />"; Microsoft.SharePoint.Client.File.SaveBinaryDirect(spContext, fileUrl, ms, true); //messsage += "CP8 <br />"; //Microsoft.SharePoint.Client.File.SaveBinaryDirect(spContext, targetFileUrl, ms, true); spContext.ExecuteQuery(); Microsoft.SharePoint.Client.File newFile = spContext.Web.GetFileByServerRelativeUrl(fileUrl); ListItem item = newFile.ListItemAllFields; ArtifactDetails attachment = new ArtifactDetails(); attachment.Function = request.Function; attachment.DocumentType = request.DocumentType; attachment.LineOfBusiness = request.LineOfBusiness; attachment.BusinessArea = request.BusinessArea; attachment.SubBusinessArea = request.SubBusinessArea; attachment.SubFunction = request.SubFunction; attachment.Tower = request.Tower; attachment.SubTower = request.SubTower; attachment.Application = request.Application; attachment.Project = request.Project; attachment.ExpiryDate = request.ExpiryDate; attachment.Keyword = request.Keyword; attachment.Comments = request.Comments; UpdateTaxonomyFields(item, attachment); response.IsError = false; response.Message = request.Name + " successfully uploaded to the KM Portal."; } } catch (Exception ex) { response.IsError = true; response.Message = "ERROR: " + ex.Message; } return(response); }
private void UpdateTaxonomyFields(ListItem item, ArtifactDetails attachment) { var ctx = item.Context; var list = item.ParentList; var fldFunction = list.Fields.GetByInternalNameOrTitle("MMFunction"); var taxFieldFunction = ctx.CastTo <TaxonomyField>(fldFunction); TaxonomyFieldValue termValueFunction = new TaxonomyFieldValue(); termValueFunction.Label = attachment.Function.Split('|')[0]; termValueFunction.TermGuid = attachment.Function.Split('|')[1]; termValueFunction.WssId = -1; taxFieldFunction.SetFieldValueByValue(item, termValueFunction); var fldDocumentType = list.Fields.GetByInternalNameOrTitle("MMDocumentType"); var taxFieldDocumentType = ctx.CastTo <TaxonomyField>(fldDocumentType); TaxonomyFieldValue termValueDocumentType = new TaxonomyFieldValue(); termValueDocumentType.Label = attachment.DocumentType.Split('|')[0]; termValueDocumentType.TermGuid = attachment.DocumentType.Split('|')[1]; termValueDocumentType.WssId = -1; taxFieldDocumentType.SetFieldValueByValue(item, termValueDocumentType); var fldLineofBusiness = list.Fields.GetByInternalNameOrTitle("MMLineofBusiness"); var taxFieldLineofBusiness = ctx.CastTo <TaxonomyField>(fldLineofBusiness); TaxonomyFieldValue termValueLineofBusiness = new TaxonomyFieldValue(); termValueLineofBusiness.Label = attachment.LineOfBusiness.Split('|')[0]; termValueLineofBusiness.TermGuid = attachment.LineOfBusiness.Split('|')[1]; termValueLineofBusiness.WssId = -1; taxFieldLineofBusiness.SetFieldValueByValue(item, termValueLineofBusiness); var fldBusinessArea = list.Fields.GetByInternalNameOrTitle("MMBusinessArea"); var taxFieldBusinessArea = ctx.CastTo <TaxonomyField>(fldBusinessArea); TaxonomyFieldValue termValueBusinessArea = new TaxonomyFieldValue(); termValueBusinessArea.Label = attachment.BusinessArea.Split('|')[0]; termValueBusinessArea.TermGuid = attachment.BusinessArea.Split('|')[1]; termValueBusinessArea.WssId = -1; taxFieldBusinessArea.SetFieldValueByValue(item, termValueBusinessArea); var fldSubBusinessArea = list.Fields.GetByInternalNameOrTitle("MMSubBusinessArea"); var taxFieldSubBusinessArea = ctx.CastTo <TaxonomyField>(fldSubBusinessArea); TaxonomyFieldValue termValueSubBusinessArea = new TaxonomyFieldValue(); termValueSubBusinessArea.Label = attachment.SubBusinessArea.Split('|')[0]; termValueSubBusinessArea.TermGuid = attachment.SubBusinessArea.Split('|')[1]; termValueSubBusinessArea.WssId = -1; taxFieldSubBusinessArea.SetFieldValueByValue(item, termValueSubBusinessArea); var fldSubFunction = list.Fields.GetByInternalNameOrTitle("MMSubFunction"); var taxFieldSubFunction = ctx.CastTo <TaxonomyField>(fldSubFunction); TaxonomyFieldValue termValueSubFunction = new TaxonomyFieldValue(); termValueSubFunction.Label = attachment.SubFunction.Split('|')[0]; termValueSubFunction.TermGuid = attachment.SubFunction.Split('|')[1]; termValueSubFunction.WssId = -1; taxFieldSubFunction.SetFieldValueByValue(item, termValueSubFunction); item["Base_x0020_Content"] = "Document"; item["Organization"] = "Insurance Technology"; item["Project_x0020_ID"] = attachment.Project; item.Update(); ctx.Load(item); ctx.ExecuteQuery(); }
public async Task <FileHandlerResponce> SubmitKM(MetaData requestp) { FileHandlerResponce fsRes = new FileHandlerResponce(); string msg = ""; try { //var itemsJson = "https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9ueWxvbmxpbmUtbXkuc2hhcmVwb2ludC5jb20vcGVyc29uYWwvc3VkZXNoX255bG9ubGluZV9vbm1pY3Jvc29mdF9jb20vRG9jdW1lbnRzL0RvY3VtZW50MTAuZG9jeD90ZW1wYXV0aD1leUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUp1YjI1bEluMC5leUpoZFdRaU9pSXdNREF3TURBd015MHdNREF3TFRCbVpqRXRZMlV3TUMwd01EQXdNREF3TURBd01EQXZibmxzYjI1c2FXNWxMVzE1TG5Ob1lYSmxjRzlwYm5RdVkyOXRRR1EyTXpjMllUaGtMVFprWTJVdE5EUTNaUzFoTVdFMUxXSmtaREJoT1RnMllXRmxOeUlzSW1semN5STZJakF3TURBd01EQXpMVEF3TURBdE1HWm1NUzFqWlRBd0xUQXdNREF3TURBd01EQXdNQ0lzSW01aVppSTZJakUxTURnNE1qZzNORGtpTENKbGVIQWlPaUl4TlRBNE9URTFNVFE1SWl3aVpXNWtjRzlwYm5SMWNtd2lPaUl3YXpsc2VUTk9Sa2xQU0dobFYzSjNPV2h6ZDFaMmVXa3dNVTFvV1VRd1VqUXpaVU5xVTBzMldreEZQU0lzSW1WdVpIQnZhVzUwZFhKc1RHVnVaM1JvSWpvaU1UQXpJaXdpYVhOc2IyOXdZbUZqYXlJNklsUnlkV1VpTENKamFXUWlPaUpOUkdSdFRtcEpNVTlYVlhSUFZFRXdUMU13TUUxRVFYZE1WR00wVDFkRmRGcEVRWGxPYWxKc1drZEtiVTlFWXpBaUxDSjJaWElpT2lKb1lYTm9aV1J3Y205dlpuUnZhMlZ1SWl3aWMybDBaV2xrSWpvaVRtMUdhMXBFVW10TmFtTjBUV3BCTUZsNU1EQlplbXQ2VEZSck1VMTZWWFJPVkZFelRtcFpORmxxV21wT2JWazFJaXdpYm1GdFpXbGtJam9pTUNNdVpueHRaVzFpWlhKemFHbHdmSE4xWkdWemFFQnVlV3h2Ym14cGJtVXViMjV0YVdOeWIzTnZablF1WTI5dElpd2libWxwSWpvaWJXbGpjbTl6YjJaMExuTm9ZWEpsY0c5cGJuUWlMQ0pwYzNWelpYSWlPaUowY25WbElpd2lZMkZqYUdWclpYa2lPaUl3YUM1bWZHMWxiV0psY25Ob2FYQjhNVEF3TXpObVptWmhOVFpsWmpsbVpVQnNhWFpsTG1OdmJTSXNJblIwSWpvaU1DSXNJblZ6WlZCbGNuTnBjM1JsYm5SRGIyOXJhV1VpT2lJeUluMC5jVEJJTVdKR01FSklSV1pQTUZFeVRIUmFjM280WTJaR1V6WjNUVVZJZUhKRFFYbE9iMWhzU1VodFZUMA/driveItem"; //var itemUrls = Session["graphUrl"].ToString(); string graphApiUrl = Session["graphUrl"].ToString(); //string graphApiUrl = itemsJson; // Initialize the GraphServiceClient. //GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(); //Getting tokenPart of the grphapi URL string toBeSearched = "shares/"; int ix = graphApiUrl.IndexOf(toBeSearched); string graphToken = ""; if (ix != -1) { graphToken = graphApiUrl.Substring(ix + toBeSearched.Length); } GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(); var request = graphClient.Shares[graphToken]; var foundFile = await request.Request().GetAsync(); MemoryStream stream = (MemoryStream)await graphClient.Me.Drive.Items[foundFile.Id].Content.Request().GetAsync(); try { string siteUrl = "https://nylonline.sharepoint.com/sites/IBM"; using (ClientContext spContext = new ClientContext(siteUrl)) { Web spWeb = spContext.Web; spContext.Credentials = new SharePointOnlineCredentials("*****@*****.**", GetSecureString("kmp@2017")); spContext.Load(spWeb); spContext.ExecuteQuery(); string title = spWeb.Title; var targetFileUrl = String.Format("{0}/{1}", "/IT Business Management Documents", foundFile.Name); stream.Position = 0; var list = spContext.Web.Lists.GetByTitle("IT Business Management Documents"); spContext.Load(list.RootFolder); spContext.ExecuteQuery(); var fileUrl = Path.Combine(list.RootFolder.ServerRelativeUrl, foundFile.Name); Microsoft.SharePoint.Client.File.SaveBinaryDirect(spContext, fileUrl, stream, true); spContext.ExecuteQuery(); //Updating MetaData Microsoft.SharePoint.Client.File newFile = spContext.Web.GetFileByServerRelativeUrl(fileUrl); ListItem item = newFile.ListItemAllFields; ArtifactDetails attachment = new ArtifactDetails(); attachment.Function = requestp.Functiont; attachment.DocumentType = requestp.DocumentType; attachment.LineOfBusiness = requestp.LineOfBusiness; attachment.BusinessArea = requestp.BusinessArea; attachment.SubBusinessArea = requestp.SubBusinessArea; attachment.SubFunction = requestp.SubFunction; attachment.Tower = requestp.Tower; attachment.SubTower = requestp.SubTower; attachment.Application = requestp.Application; attachment.Project = requestp.Project; if (requestp.ExpiryDate == string.Empty) { attachment.ExpiryDate = null; } else { attachment.ExpiryDate = Convert.ToDateTime(requestp.ExpiryDate); } attachment.Keyword = requestp.Keyword; attachment.Comments = requestp.Comments; UpdateTaxonomyFields(item, attachment); fsRes.IsError = false; fsRes.Message = "Successfully Uploaded!"; } } catch (Exception ex) { fsRes.IsError = true; fsRes.Message = ex.Message; msg = ex.Message; } } catch (ServiceException se) { fsRes.IsError = true; fsRes.Message = se.Message; msg = se.Message; } msg = "OK"; return(fsRes); }