пятница, 21 ноября 2008 г.

Walking through Enum entries in C#


Sometimes the need appears in make foreach() construction for Enum entries. Here I'll show how to do it.



Type theType = typeof(MyEnum);
MemberInfo[] theMembers = theType.GetMembers();

foreach (MemberInfo entry in theMembers)
{
if ((entry.MemberType.ToString() == "Field"))
if((entry.Name != "value__"))
{
MyEnum theTyp = (MyEnum)Enum.Parse(typeof(MyEnum), entry.Name);
}
}


As earlier I'm trying to present finished solutions ready to use in your own projects. :)

пятница, 7 ноября 2008 г.

C# numeric format string with fixed length


Do you want to get from 'int' value 'string' representation with fixed length?
Here is solution:) Example:


int iVal = 53;
string strVal = iVal.ToString("0000");


Result:
0053


Enjoy:)


пятница, 24 октября 2008 г.

Create Registry Path in PowerShell


Here is script to create registry path (or separate key) in PowerShell



function vrIsRegistryPathContainsKey($basePath, $key)
{
if($key.Length -le 0)
{ return 0 }

$childItems = Get-ChildItem $basePath -Force -ErrorAction SilentlyContinue
foreach ($childItem in $childItems)
{
if($childItem.name -match $key)
{
return 1
}
}
return 0
}

function vrCreateRegistryPath($basePath, $createdPath)
{
$pathTokens = $createdPath.split("\")
foreach ($pathToken in $pathTokens)
{
if($pathToken.Length -le 0)
{ break }

if(-not(vrIsRegistryPathContainsKey $basePath $pathToken))
{
echo ('not found ' + $pathToken);
New-Item -Path $basePath -Name $pathToken
}
$basePath = $basePath + "\" + $pathToken
echo ('basepath ' + $basePath);
}
}


Usage:
vrCreateRegistryPath 'Microsoft.PowerShell.Core\Registry::\HKEY_LOCAL_MACHINE\SOFTWARE' 'Key\SubKey1\Subkey2\'


вторник, 21 октября 2008 г.

Veeam Reporter v.3.0 Enterprise Release


We did it! Veeam Reporter v.3.0 Enterprise for VMware infrastructure 3 has been released today. See more...

Using .NET Enum values in PowerShell


For using values of enum nested in type and/or namespace of already loaded assembly in PowerShell you would use following statement:


[SomeNamespace.EnclosingType+NestedEnum]::EnumValue


пятница, 22 августа 2008 г.

CarlosAg.ExcelXmlWriter: freeze top row










For freeze top row in Microsoft Excel 2007 worksheet using CarlosAg.ExcelXmlWriter
from CarlosAg Excel Xml Writer Library use following code:

Workbook myWorkBook = new Workbook();
Worksheet myWorksheet = myWorkBook.Worksheets.Add("Data");
myWorksheet.Options.Selected = true;
myWorksheet.Options.FreezePanes = true;
myWorksheet.Options.SplitHorizontal = 1;
myWorksheet.Options.TopRowBottomPane = 1;
myWorksheet.Options.ActivePane = 2;

Also you can use CarlosAg.ExcelXmlWriter.Generator.exe from CarlosAg Excel Xml Writer Library for get c# code for Excel *.xml files saved in XML Spreadsheet format.

вторник, 19 августа 2008 г.

Microsoft.Office.Interop.Excel reference isn't resolved

For .net developers which works with MS Office interop, maybe following information would seem useful. Did you happen to face with unresolved Office Interop references?
Each time as I saw this strange phenomena I would need some magic to resolve the problem.
Mostly the reason hides in conflicting of different asseblies references. In this case usually it's better to remove all unresolved references and add each new assembly refererence step-by-step checking conflict absence.