private static void DeleteMissingFile(MissingWorkflowAssociationsInput missingFile, string csvFile) { bool headerWAOP = false; MissingWorkflowAssociationsOutput objWFOP = new MissingWorkflowAssociationsOutput(); if (missingFile == null) { return; } string wfFileDirName = missingFile.DirName; string wfFileName = missingFile.LeafName; string webAppUrl = missingFile.WebApplication; string webUrl = missingFile.WebUrl; objWFOP.DirName = wfFileDirName; objWFOP.LeafName = wfFileName; objWFOP.WebApplication = webAppUrl; objWFOP.WebUrl = webUrl; objWFOP.SiteCollection = missingFile.SiteCollection; objWFOP.ExecutionDateTime = DateTime.Now.ToString(); if (webUrl.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) < 0) { // ignore the header row in case it is still present return; } // clean the inputs if (wfFileDirName.EndsWith("/")) { wfFileDirName = wfFileDirName.TrimEnd(new char[] { '/' }); } if (!wfFileDirName.StartsWith("/")) { wfFileDirName = "/" + wfFileDirName; } if (wfFileName.StartsWith("/")) { wfFileName = wfFileName.TrimStart(new char[] { '/' }); } if (webUrl.EndsWith("/")) { webUrl = webUrl.TrimEnd(new char[] { '/' }); } if (webAppUrl.EndsWith("/")) { webAppUrl = webAppUrl.TrimEnd(new char[] { '/' }); } // e.g., "https://ppeTeams.contoso.com/sites/test/_catalogs/masterpage/Sample.master" string serverRelativeFilePath = wfFileDirName + '/' + wfFileName; try { Logger.LogInfoMessage(String.Format("\n\n[DeleteMissingWorkflowAssociations: DeleteMissingFile] Processing Workflow Association File: {0} ...", webAppUrl + serverRelativeFilePath), true); // we have to open the web because Helper.DeleteFileByServerRelativeUrl() needs to update the web in order to commit the change using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, webUrl)) { Web web = userContext.Web; userContext.Load(web); userContext.ExecuteQuery(); if (Helper.DeleteFileByServerRelativeUrl(web, serverRelativeFilePath)) { Logger.LogInfoMessage(wfFileName + " deleted successfully and output file is present in the path: " + Environment.CurrentDirectory); objWFOP.Status = Constants.Success; } else { objWFOP.Status = Constants.Failure; } //Logger.LogInfoMessage(targetFile.Name + " deleted successfully"); } if (System.IO.File.Exists(csvFile)) { headerWAOP = true; } FileUtility.WriteCsVintoFile(csvFile, objWFOP, ref headerWAOP); } catch (Exception ex) { Logger.LogErrorMessage(String.Format("[DeleteMissingWorkflowAssociations: DeleteMissingFile] failed for {0}: Error={1}", serverRelativeFilePath, ex.Message), true); ExceptionCsv.WriteException(webAppUrl, Constants.NotApplicable, webUrl, "WorkflowAssociations", ex.Message, ex.ToString(), "DeleteMissingFile", ex.GetType().ToString(), String.Format("DeleteMissingWorkflowAssociationFile() failed for {0}: Error={1}", serverRelativeFilePath, ex.Message)); } }
private static void DeleteMissingFile(MissingWorkflowAssociationsInput missingFile) { if (missingFile == null) { return; } string wfFileDirName = missingFile.DirName; string wfFileName = missingFile.LeafName; string webAppUrl = missingFile.WebApplication; string webUrl = missingFile.WebUrl; if (webUrl.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) < 0) { // ignore the header row in case it is still present return; } // clean the inputs if (wfFileDirName.EndsWith("/")) { wfFileDirName = wfFileDirName.TrimEnd(new char[] { '/' }); } if (!wfFileDirName.StartsWith("/")) { wfFileDirName = "/" + wfFileDirName; } if (wfFileName.StartsWith("/")) { wfFileName = wfFileName.TrimStart(new char[] { '/' }); } if (webUrl.EndsWith("/")) { webUrl = webUrl.TrimEnd(new char[] { '/' }); } if (webAppUrl.EndsWith("/")) { webAppUrl = webAppUrl.TrimEnd(new char[] { '/' }); } // e.g., "https://ppeTeams.contoso.com/sites/test/_catalogs/masterpage/Sample.master" string serverRelativeFilePath = wfFileDirName + '/' + wfFileName; try { Logger.LogInfoMessage(String.Format("\n\nProcessing Workflow Association File: {0} ...", webAppUrl + serverRelativeFilePath), true); // we have to open the web because Helper.DeleteFileByServerRelativeUrl() needs to update the web in order to commit the change using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, webUrl)) { Web web = userContext.Web; userContext.Load(web); userContext.ExecuteQuery(); Helper.DeleteFileByServerRelativeUrl(web, serverRelativeFilePath); //Logger.LogInfoMessage(targetFile.Name + " deleted successfully"); } } catch (Exception ex) { Logger.LogErrorMessage(String.Format("DeleteMissingWorkflowAssociationFile() failed for {0}: Error={1}", serverRelativeFilePath, ex.Message), false); } }