private void ExportComputerstoCSV(string stringFileName) { // File FileStream1 = new System.IO.File(); StringBuilder StringBuilder1 = new StringBuilder(null); foreach (string string1 in Computer.StringArrayComputerProperties) { if (StringBuilder1.Length == 0) { StringBuilder1.Append(string1); } StringBuilder1.Append(',' + string1); } StringBuilder1.AppendLine(); foreach (Computer Computer1 in Computers1) { StringBuilder StringBuilderTemp = new StringBuilder(null); foreach (string string1 in Computer1.Properties()) { if (StringBuilderTemp.Length == 0) { StringBuilderTemp.Append(string1); } StringBuilderTemp.Append(',' + string1); } // StringBuilder1.AppendLine(); StringBuilder1.AppendLine(StringBuilderTemp.ToString()); } File.WriteAllText(stringFileName, StringBuilder1.ToString(), Encoding.UTF8); MessageBox.Show("Saved Successfully", "Active Directory", MessageBoxButton.OK, MessageBoxImage.Information); }
private void ExportComputerstoExcel(string stringFileName) { Excel._Application ExcelApplication; Excel.Workbook ExcelWorkbook; Excel.Worksheet ExcelWorksheet; object objectMisValue = System.Reflection.Missing.Value; Excel.Range ExcelRangeCellinstance; ExcelApplication = new Excel.Application(); ExcelWorkbook = ExcelApplication.Workbooks.Add(objectMisValue); ExcelWorksheet = (Excel.Worksheet)ExcelWorkbook.Worksheets.get_Item(1); ExcelApplication.DisplayAlerts = false; ExcelRangeCellinstance = ExcelWorksheet.get_Range("A1", Type.Missing); int intRow = 1; int intColumn = 1; foreach (string string1 in Computer.StringArrayComputerProperties) { ExcelWorksheet.Cells[intRow, intColumn] = string1; intColumn++; } intRow++; foreach (Computer Computer1 in Computers1) { intColumn = 1; foreach (string string1 in Computer1.Properties()) { ExcelWorksheet.Cells[intRow, intColumn] = string1; intColumn++; } intRow++; } //Highlight first row Excel.Range ExcelRange1 = ExcelWorksheet.get_Range("A1", Type.Missing); ExcelRange1.EntireRow.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black); ExcelRange1.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightSkyBlue); ExcelRange1.EntireRow.Font.Size = 14; ExcelRange1.EntireRow.AutoFit(); //Save Excel ExcelWorkbook.SaveAs(stringFileName, Excel.XlFileFormat.xlWorkbookNormal, objectMisValue, objectMisValue, objectMisValue, objectMisValue, Excel.XlSaveAsAccessMode.xlExclusive, objectMisValue, objectMisValue, objectMisValue, objectMisValue, objectMisValue); ExcelWorkbook.Close(); MessageBox.Show("Saved Successfully", "Active Directory", MessageBoxButton.OK, MessageBoxImage.Information); }