Thanks alot, worked perfect, and i learned one new thing! :) Have a good day!
jwradhe
Posts
-
Problems when reading a Excel file with numbers. -
Problems when reading a Excel file with numbers.Hi! When i run my code with a excel document with words in, it works, but at fast as i read a document with numbers only i get error on marked line in code.
if (c.DataType.Value == CellValues.SharedString)
and the error is:
An error occurred!!!: The object reference has not been specified to an instance of an object.
I have a little hard to see why this happends, hope on you experts!
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(input, true))
{WorkbookPart workbookPart = myDoc.WorkbookPart; WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); SheetData sheetData = worksheetPart.Worksheet.Elements().First(); foreach (Row r in sheetData.Elements()) { foreach (Cell c in r.Elements()) { string value = c.InnerText; **if (c.DataType.Value == CellValues.SharedString)** { var stringTable = workbookPart.GetPartsOfType() .FirstOrDefault(); if (stringTable != null) { value = stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText; GenerateBarcodeFromExcel(value, output); } } else { GenerateBarcodeFromExcel(c.CellValue.Text, output); } } } myDoc.Close();
-
c# Search in root/subtree active directory usersHi!
Im having some problem in my function to search on all users in my active directory, root and subtree.my ad is like this:
ad.company
-> se.ad.company
-> fin.ad.company
-> no.ad.companyI can search , but only get some results from ad.company, not the other subtree directorys.
What have i done wrong?And this is my code:
private void AutoCompleteTextBox_ReferenceUser()
{try { var attributeName = "sn"; string OU = "DC=ad,DC=company"; var searchString = textBox\_manager.Text; var ent = new DirectoryEntry("GC://" + OU); var mySearcher = new DirectorySearcher(ent); mySearcher.Filter = string.Format("(&(anr={0})(objectCategory=user)(objectClass=user))", attributeName, searchString); SearchResultCollection result = mySearcher.FindAll(); List names = new List(); foreach(SearchResult sr in result) { var n = sr.Properties\["cn"\]\[0\].ToString(); if (!names.Contains(n)) { stringCollection.Add(n); } } textBox\_referenceuser.AutoCompleteMode = AutoCompleteMode.Suggest; textBox\_referenceuser.AutoCompleteSource = AutoCompleteSource.CustomSource; textBox\_referenceuser.AutoCompleteCustomSource = stringCollection; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
-
Run powershell in C#2021-09-20 is the result from PS command
-
Run powershell in C#Hi! Yeah if possible i want it in C# only. I trid the code but i gives this: 0001-01-01 00:00:00 +00:00
-
Run powershell in C#Hi! I am pretty new to this, but im trying to present when the latest winupdate was done on computer, and only found in powershell to present that, and i tried to run it in C#, but no error and no result. I understand that im doing wrong, but what is the best way to do this?
// Get Latest Windows Update
private void LastWinUpd()
{Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; //ps.Commands.AddScript("gwmi win32\_quickfixengineering | Select-Object -expandProperty 'installedon' | sort installedon -desc | Select-Object -First 1 | Get-Date -Format 'yyyy - MM - dd K'"); ps.AddCommand("$a = (New - Object - com 'Microsoft.Update.AutoUpdate').Results"); ps.AddCommand("$a.LastInstallationSuccessDate | Get - Date - Format 'yyyy-MM-dd K'"); Collection results = ps.Invoke(); runspace.Close(); StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { text\_LastWinUpd.Text = obj.ToString(); } } // END
-
Run powershell in C#Hi! I am pretty new to this, but im trying to present when the latest winupdate was done on computer, and only found in powershell to present that, and i tried to run it in C#, but no error and no result. I understand that im doing wrong, but what is the best way to do this?
// Get Latest Windows Update
private void LastWinUpd()
{Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; //ps.Commands.AddScript("gwmi win32\_quickfixengineering | Select-Object -expandProperty 'installedon' | sort installedon -desc | Select-Object -First 1 | Get-Date -Format 'yyyy - MM - dd K'"); ps.AddCommand("$a = (New - Object - com 'Microsoft.Update.AutoUpdate').Results"); ps.AddCommand("$a.LastInstallationSuccessDate | Get - Date - Format 'yyyy-MM-dd K'"); Collection results = ps.Invoke(); runspace.Close(); StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { text\_LastWinUpd.Text = obj.ToString(); } } // END