System.Security.SecureString HowTo

Today I’ve had to look at System.Security.SecureString to store passwords. I would have never in my wildest dreams thought that you will have to use System.Runtime.InteropServices.Marshal to convert the SecureString value to an IntPtr and then convert that back to string.

Example:

public SecureString Value
{           get;       
   set;
}
public void DisplaySecureString()
{
   var valuePtr = Marshal.SecureStringToBSTR( Value );
   var stringValue = Marshal.PtrToStringBSTR( valuePtr );
   Console.WriteLine( stringValue );
}

 
Posted in .Net, C# | Tagged , , | Leave a comment

How to delete a Project in Team Foundation Server (TFS)

Open Visual Studio Command Prompt (2008), (2010), etc…

TFS 2008 and below:

TFSDeleteProject /server:ServerName ProjectName

TFS 2010 and above:

TFSDeleteProject /collection:http[s]://Servername:port/tfs “Project Name”

Warning: Deleting a team project is an irrecoverable operation. All version control, work item tracking and Team Foundation build data will be destroyed from the system. The only way to recover this data is by restoring a stored backup of the databases.

Posted in TFS | Leave a comment

30 Free Programming books

While browsing the interwebs I found the following site where you can get 30 free programming books.

Cheers

Posted in General | Leave a comment

Sync Framework 4.0 now supports any platform. iPhone, Android, Blackberry, etc…

Sync Framework 2.1 required clients to be based on Windows. This toolkit allows other Microsoft platforms to be used for offline clients such as Silverlight, Windows Phone 7, and Windows Mobile; in addition non-Microsoft platforms such as iPhone, Android, and Blackberry can be utilized as well as HTML.

More information can be found here.

Posted in General | Leave a comment

Word Embedded PDF AcroExch error

I few days ago a client sent me a document with a PDF embedded in it. I was unable open by double clicking on the embedded PDF icon. I searched for a solution and found the following link http://community.spiceworks.com/topic/post/627705 and it show me how to fix it.

http://www.activesearchresults.com 

Posted in General | 1 Comment

Silverlight DataGrid – Add new Row

Microsoft release a service pack for Silverligth 4.0 which now allows the Silverlight DataGrid to display a new row at the bottom of the grid.

Important to me is:

Issue 2 – This update enables new Add Row functionality in the Silverlight DataGrid control.
,Issue 7 – Fixed various memory leaks including:

  • Memory leaks that occur when mouse capture is used. For example, memory leaks that occur when you use CaptureMouse() in drag-and-drop scenarios. For more information, see the following Microsoft Silverlight forums discussion.
  • Memory leaks that occur when UserControl cannot be garbage-collected because it contains inline data template. For more information, see the following Microsoft Silverlight forums discussion.

The have also fixed 5 other issues for more information goto KB2164913.

Get the bits here…

08-Sep-2010 – Update:

For the New line to work you have to implement the System.ComponentModel.ICollectionView interface.

Posted in General | Leave a comment

Mindscape – Released nHibernate Designer

Mindscape just an excellent DSL for nHibernate goto Mindscape.co.nz to get all the goodness.

Posted in General, Tools | Leave a comment

VS2010 crashing when switching to Design view

Microsoft released a hotfix for Visual Studio 2010 that will hopefully resolve most of the crashes

Get the hotfix from KB2201993 – VS2010 crashing when switching to Design viewhere.

Posted in General | Leave a comment

Databinding Current Item

Since I’ve started in with WPF (2007) I’ve seen many people creating Validation.ErrorTemplates with the following Binding to display the error message

{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}

When this binding is used you will see the following errors appear in the Debug Output window:

System.Windows.Data Error: 16 : Cannot get ‘Item[]‘ value (type ‘ValidationError’) from ‘(Validation.Errors)’ (type ‘ReadOnlyObservableCollection`1′). BindingExpression:Path=AdornedElement.(0).[0].ErrorContent; DataItem=’AdornedElementPlaceholder’ (Name=’customAdorner’); target element is ‘TextBlock’ (Name=”); target property is ‘ToolTip’ (type ‘Object’) TargetInvocationException:’System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index)
— End of inner exception stack trace —
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)’

When you change the Binding from

{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}

To

{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)/ErrorContent}

All the exception related to the [0] will be a thing of the past as the / will bind to the current item of the collection and will not cause a any errors if there is no current item.

This could also be used when you have a collection of items and want to display the current item’s properties on a UI (View).

Hope this post can help other people.

Kind regards,

Johan J v Rensburg

Example Source Code: DataBinding CurrentItem.rename_to_zip

Posted in WPF | Tagged | 1 Comment

Free giveaway from Mindscape for the first 50 members

Mindscape is giving away Visual Tools for SharePoint for the first 50 users click here. Hurry up times running out.

Posted in Tools | Tagged , | Leave a comment