DCSIMG
C# - David Birin's blog

Browse by Tags

WPF Auto-scroll ListBox
The WPF’s ListBox is a great control with infinite ways to design the items template, but I found that is lacks one important feature: AutoScroll. I had to use a control that shows messages which are received in runtime, so I had to add this functionality because the user needs to see the newest messages, I also gave the ability to stop the AutoScroll using a DependencyProperty and using this ability I wrote a trigger that stops the scrolling when the mouse is over the ListBox (imagine trying to...
Why can’t we be friends (Assemblies)?
This great song asks “why can’t we be friends?” well after working 5 years in .NET I found out that assemblies can be friends… So what are friend assemblies, well it's pretty simple, it’s a way of giving another assembly access to the internal members on an assembly, and yes, it reminds me of C++ friend classes, but in C++ a friend has access to private members and in .NET only to internal members. I created a new assembly in C# and I want other assemblies to access it internal members. namespace...
C# anticelebrities – Part 1 – The ?? operator
I decided to start a new series of posts on the anticelebrities operators / keywords of C#,  being anticelebrity for a keyword / operator means that it’s not widely used by programmers. Some may say that main purpose of the members in the anticelebrity club is to be used in tricky interview questions, I hope that I will give them a push towards celebritness by explaining how to use them, at the worst case you will have some geek trivia questions for your next coffee break.   The ?? operator...
Embedded resources in XSL files
If you ever worked with embedded resources you probably know the required steps for embedding resources: Setting the build action to “Embedded Resource” in the file properties. Adding a web resource attribute with the file (best practice is to add this line in the AssemblyInfo.cs file) the first parameter is the default project namespace + the filename and the second parameter is the mime-type: [assembly: WebResource( "Namespace.Filename.gif" , "image/gif" )] The WebResource attribute...
SharePoint – Events are duplicated when using templates
I encountered a strange behavior in SharePoint, this phenomenon happens when you create an event handler and attach it to a list template (for example, a document library) using a web-site level feature. If you save the list as template, the event handler reference is saved inside the list template (STP file) and when you create an instance using the template it can cause the following problems: The event handler will be activated automatically on a web site where the feature is not enabled. If the...
SharePoint – Add a SPField to all the content types in a SPList
I found out (another) strange behavior of SharePoint, I tried to add a field (a column) to a list which contain more than one content type using the following code (the new field name is “New Field”) : using (SPSite currentSite = new SPSite( "http://moss" )) { using (SPWeb currentWeb = currentSite.OpenWeb()) { SPList currentList = currentWeb.Lists[ "DocLib" ]; SPField newField = currentList.Fields.CreateNewField(SPFieldType.Text.ToString(), "New Field" ); currentList...
SharePoint - Internal field names in Hebrew
A field (sometimes called a column) in SharePoint - represented in the object model by the SPField class, has two main properties which are used to identify it in code, the Title property and the InternalName property, the reason for the duplication is that the Title property can be changed from the GUI or translated into other languages, therefore if we want to write code which can be used without recompiling after every field name change in the GUI or recompiling for different languages we will...
How to create an application in IIS6 using C#
Before the IIS7 era, we had no API for directly manipulating IIS, but we still needed to perform some actions like creating a virtual directory or an application (mostly used in installations). Creating an application using the IIS GUI is done in the following way:   Creating it in code is a more complex task which is dived into 3 parts: 1. Finding the website in the IIS which we want to create the application underneath: /// <summary> /// This function looks for the path of a web site...