public void DeleteWebPart_UsingCSV(string sourceWebPartType, string usageFileName, string outPutFolder, string csvFile, string SharePointOnline_OR_OnPremise = "N/A", string UserName = "******", string Password = "******", string Domain = "N/A") { string exceptionCommentsInfo1 = string.Empty; try { WebPart_Initialization(outPutFolder); Logger.AddMessageToTraceLogFile(Constants.Logging, "############## Web Part Trasnformation Utility Execution Started - DeleteWebPart_UsingCSV - For InputCSV ##############"); Console.WriteLine("############## Web Part Trasnformation Utility Execution Started - DeleteWebPart_UsingCSV - For InputCSV ##############"); Logger.AddMessageToTraceLogFile(Constants.Logging, "[DATE TIME] " + Logger.CurrentDateTime()); Console.WriteLine("[DATE TIME] " + Logger.CurrentDateTime()); Logger.AddMessageToTraceLogFile(Constants.Logging, "[DeleteWebPart_UsingCSV] Initiated Logger and Exception Class. Logger and Exception file will be available in path" + outPutFolder); Console.WriteLine("[DeleteWebPart_UsingCSV] Initiated Logger and Exception Class. Logger and Exception file will be available in path" + outPutFolder); //Reading Input File IEnumerable<WebPartDiscoveryInput> objWPDInput; ReadWebPartUsageCSV(sourceWebPartType, usageFileName, outPutFolder, out objWPDInput, SharePointOnline_OR_OnPremise, UserName, Password, Domain); bool headerTransformWebPart = false; if (objWPDInput.Any()) { for (int i = 0; i < objWPDInput.Count(); i++) { WebPartDiscoveryInput objInput = objWPDInput.ElementAt(i); TranformWebPartStatusBase objWPOutputBase = new TranformWebPartStatusBase(); try { SetExceptionCSVWebAppSiteColWebUrls(objInput.WebUrl.ToString(), SharePointOnline_OR_OnPremise, UserName, Password, Domain); //This is for Exception Comments: exceptionCommentsInfo1 = "WebUrl: " + objInput.WebUrl + ", ZoneID: " + objInput.ZoneID + ", StorageKey" + objInput.StorageKey; //This is for Exception Comments: bool status = DeleteWebPart(objInput.WebUrl, objInput.PageUrl.ToString(), objInput.StorageKey, outPutFolder, SharePointOnline_OR_OnPremise, UserName, Password, Domain, Constants.ActionType_CSV.ToLower()); if (status) { objWPOutputBase.Status = "Successfully Deleted WebPart"; } else { objWPOutputBase.Status = "Failed to Deleted WebPart"; } } catch (Exception ex) { objWPOutputBase.Status = "Failed to Deleted WebPart"; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error in Processing Web:" + ExceptionCsv.WebUrl + " `\r\nError Details:" + ex.Message + " `\r\nExceptionComments:" + exceptionCommentsInfo1); Console.ForegroundColor = ConsoleColor.Gray; Logger.AddMessageToTraceLogFile(Constants.Logging, "[Exception][DeleteWebPart_UsingCSV] Exception Message: " + ex.Message); ExceptionCsv.WriteException(ExceptionCsv.WebApplication, ExceptionCsv.SiteCollection, ExceptionCsv.WebUrl, "Web Part", ex.Message, ex.ToString(), "DeleteWebPart_UsingCSV", ex.GetType().ToString(), exceptionCommentsInfo1); } objWPOutputBase.WebPartType = objInput.WebPartType; objWPOutputBase.ZoneID = objInput.ZoneID; objWPOutputBase.ZoneIndex = objInput.ZoneIndex; objWPOutputBase.WebPartId = objInput.WebPartId; objWPOutputBase.PageUrl = objInput.PageUrl; objWPOutputBase.WebUrl = ExceptionCsv.WebUrl; objWPOutputBase.SiteCollection = ExceptionCsv.SiteCollection; objWPOutputBase.WebApplication = ExceptionCsv.WebApplication; if (System.IO.File.Exists(csvFile)) { headerTransformWebPart = true; } FileUtility.WriteCsVintoFile(csvFile, objWPOutputBase, ref headerTransformWebPart); } } Logger.AddMessageToTraceLogFile(Constants.Logging, "############## Web Part Trasnformation Utility Execution Completed - DeleteWebPart_UsingCSV - InputCSV ##############"); Console.WriteLine("############## Web Part Trasnformation Utility Execution Completed - DeleteWebPart_UsingCSV - InputCSV ##############"); } catch (Exception ex) { Logger.AddMessageToTraceLogFile(Constants.Logging, "[Exception] FUNCTION DeleteWebPart_UsingCSV. Exception Message: " + ex.Message); ExceptionCsv.WriteException(ExceptionCsv.WebApplication, ExceptionCsv.SiteCollection, ExceptionCsv.WebUrl, "Web Part", ex.Message, ex.ToString(), "DeleteWebPart_UsingCSV", ex.GetType().ToString(), exceptionCommentsInfo1); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[Exception] FUNCTION DeleteWebPart_UsingCSV. Exception Message: " + ex.Message); Console.ForegroundColor = ConsoleColor.Gray; } }
public void AddWebPart_UsingCSV(string sourceWebPartType, string targetWebPartFileName, string targetWebPartXmlDir, string usageFileName, string outPutFolder, string SharePointOnline_OR_OnPremise = "N/A", string UserName = "******", string Password = "******", string Domain = "N/A") { string exceptionCommentsInfo1 = string.Empty; try { WebPart_Initialization(outPutFolder); Logger.AddMessageToTraceLogFile(Constants.Logging, "############## Web Part Trasnformation Utility Execution Started - AddWebPart - For InputCSV ##############"); Console.WriteLine("############## Web Part Trasnformation Utility Execution Started - AddWebPart - For InputCSV ##############"); Logger.AddMessageToTraceLogFile(Constants.Logging, "[DATE TIME] " + Logger.CurrentDateTime()); Console.WriteLine("[DATE TIME] " + Logger.CurrentDateTime()); Logger.AddMessageToTraceLogFile(Constants.Logging, "[AddWebPart_UsingCSV] Initiated Logger and Exception Class. Logger and Exception file will be available in path" + outPutFolder); Console.WriteLine("[AddWebPart_UsingCSV] Initiated Logger and Exception Class. Logger and Exception file will be available in path" + outPutFolder); //Reading Input File IEnumerable<WebPartDiscoveryInput> objWPDInput; ReadWebPartUsageCSV(sourceWebPartType, usageFileName, outPutFolder, out objWPDInput, SharePointOnline_OR_OnPremise, UserName, Password, Domain); bool headerTransformWebPart = false; bool status = false; if (objWPDInput.Any()) { for (int i = 0; i < objWPDInput.Count(); i++) { try { WebPartDiscoveryInput objInput = objWPDInput.ElementAt(i); SetExceptionCSVWebAppSiteColWebUrls(objInput.WebUrl.ToString(), SharePointOnline_OR_OnPremise, UserName, Password, Domain); //This is for Exception Comments: exceptionCommentsInfo1 = "WebUrl: " + objInput.WebUrl + ", ZoneID: " + objInput.ZoneID; //This is for Exception Comments: //This function is Get Relative URL of the page string _relativePageUrl = string.Empty; _relativePageUrl = GetPageRelativeURL(objInput.WebUrl.ToString(), objInput.PageUrl.ToString(), SharePointOnline_OR_OnPremise, UserName, Password, Domain); string _storageKey = string.Empty; _storageKey = GetWebPartID(objInput.StorageKey); //sourceWebPartId - Used to update the content of the wikipage with new web part id [Fix for BugId - 95007] string _webPartId = string.Empty; _webPartId = GetWebPartID(objInput.WebPartId); //End string _targetWebPartXml = string.Empty; _targetWebPartXml = GetTargetWebPartXmlFilePath(_storageKey, targetWebPartXmlDir); if (_targetWebPartXml != "") { status = AddWebPart(objInput.WebUrl, targetWebPartFileName, _targetWebPartXml, objInput.ZoneIndex, objInput.ZoneID, _relativePageUrl, outPutFolder, SharePointOnline_OR_OnPremise, UserName, Password, Domain, Constants.ActionType_CSV.ToLower(), _webPartId); } else { Logger.AddMessageToTraceLogFile(Constants.Logging, "[AddWebPart_UsingCSV] Target WebPartXml File: " + targetWebPartFileName + " does not exists for StorageKey" + _storageKey + "in Path(TargetWebPartXmlDir): " + targetWebPartXmlDir + " for page " + _relativePageUrl); Console.WriteLine("[AddWebPart_UsingCSV] Target WebPartXml File: " + targetWebPartFileName + " does not exists for StorageKey" + _storageKey + "in Path(TargetWebPartXmlDir): " + targetWebPartXmlDir + " for page " + _relativePageUrl); } TranformWebPartStatusBase objWPOutputBase = new TranformWebPartStatusBase(); objWPOutputBase.WebUrl = objInput.WebUrl; objWPOutputBase.WebPartType = objInput.WebPartType; objWPOutputBase.ZoneID = objInput.ZoneID; objWPOutputBase.ZoneIndex = objInput.ZoneIndex; objWPOutputBase.WebPartId = objInput.WebPartId; objWPOutputBase.PageUrl = objInput.PageUrl; if (status) { objWPOutputBase.Status = "Successfully Added WebPart"; } else { objWPOutputBase.Status = "Failed to Add WebPart"; } FileUtility.WriteCsVintoFile(outPutFolder + @"\" + System.IO.Path.GetFileNameWithoutExtension(usageFileName) + "_AddOperationStatus.csv", objWPOutputBase, ref headerTransformWebPart); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error in Processing Web:" + ExceptionCsv.WebUrl + " `\r\nError Details:" + ex.Message + " `\r\nExceptionComments:" + exceptionCommentsInfo1); Console.ForegroundColor = ConsoleColor.Gray; Logger.AddMessageToTraceLogFile(Constants.Logging, "[Exception][ReplaceWebPart_UsingCSV] Exception Message: " + ex.Message); ExceptionCsv.WriteException(ExceptionCsv.WebApplication, ExceptionCsv.SiteCollection, ExceptionCsv.WebUrl, "Web Part", ex.Message, ex.ToString(), "ReplaceWebPart_UsingCSV", ex.GetType().ToString(), exceptionCommentsInfo1); } } } Logger.AddMessageToTraceLogFile(Constants.Logging, "############## Web Part Trasnformation Utility Execution Completed - AddWebPart - InputCSV ##############"); Console.WriteLine("############## Web Part Trasnformation Utility Execution Completed - AddWebPart - InputCSV ##############"); } catch (Exception ex) { Logger.AddMessageToTraceLogFile(Constants.Logging, "[Exception] [AddWebPart_UsingCSV] Exception Message: " + ex.Message); ExceptionCsv.WriteException(ExceptionCsv.WebApplication, ExceptionCsv.SiteCollection, ExceptionCsv.WebUrl, "Web Part", ex.Message, ex.ToString(), "AddWebPart_UsingCSV", ex.GetType().ToString(), exceptionCommentsInfo1); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[Exception][AddWebPart_UsingCSV] Exception Message: " + ex.Message); Console.ForegroundColor = ConsoleColor.Gray; } }