DCSIMG
DEV - 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...
Different behaviors between select to variable in SQL
I encountered different behaviors between the two syntaxes of select to variable in SQL. The first type of select has the following syntax: SELECT @ Variable = C FROM T and the second syntax: SET @ Variable = ( SELECT C FROM T) When the query result is a single value the behavior of both is the same (as expected the query result will be placed into the variable). Things become more difficult when the query returns more than one result, or zero results as can be seen in the following examples: For...
Why do ASP.NET sessions not shared between multiple IE processes
It was always one of the axioms in the back of my mind that when you open a window in Internet Explorer using Ctrl+N it has the same session in ASP.NET apps like it’s parent window, but if you run a new process of Internet Explorer it has a different session. Well… today I had to check why does it happen. The first step is to get familiar with two different kinds of cookies: the first is a cookie with an expiration date (AKA persistent cookie ) this cookie will be saved to the disk and will be available...
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...
Entity Framework in a SOA environment
I received a mission to explore entity framework as a DAL for a new project, this project is intended to be N-Tier SOA application. Here are some of my findings: The partial classes which are created by entity framework already contain DataContract and DataMember attributes and are “ready to use” in WCF. Entity framework has a change tracking mechanism, the main problem with this mechanism is that once the object was serialized (before transferred in a service) it gets the state “detached” and from...
MOSS Excel Services – Trusted Data Connection “/” makes the difference
Here is a problem that can be solved in seconds or you can spend few hours trying to solve it and bang your head against the screen (like I did…) when you find how easy is the solution. I had to configure an Excel service, the Excel file included data connection reference to an MSAS cube. After adding the Excel file, setting the trusted file location, the trusted data location and the security of the data connection, I still got the following error message:   As I said before I did a lot of...
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...
MOSS – Open search results for editing (Office 2003/7)
I visited a customer which wanted the option to directly open a document from the search results for editing (in default when you click a document from the search results it opens as read-only). I found this blog article which describes how to do it by embedding some JavaScript into the search results XSL, I did exactly as described and it didn’t work, I realized that this happens because this customer uses Office 2003. I had to do some digging using the IE developer toolbar (soon to be an integral...
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...