Posts Tagged ‘C#’

Syncfusion Report Viewer Control

Written by rsolberg. Posted in All, Software Development, Technology

I’ve recently been exploring many of the Syncfusion controls and one that jumped out to me as potentially being very useful is the Report Viewer control. Many companies and development shops out there want to make you think they are the ones who have nailed the perfect reporting platform and the fact of the matter is I don’t believe any of them have truly nailed anything. I’m not saying their products are garbage, I’m simply pointing out the obvious that is not obvious. You see every project and every business demand is unique and having a one size fits all approach is difficult. Larger organizations attempt to work around this by having huge investments into database systems from Oracle and Microsoft with nice reporting features like SQL Reporting Services. But what about small businesses without the capital to invest into these platforms?

Entity Framework Seed Data for States & Counties

Written by rsolberg. Posted in All, Software Development, Technology

One of the great benefits of Entity Framework and Code First for ASP.NET MVC application development is the ability to seed data for your application when you run your application for the first time. Earlier today I was working on an implementation of EF and Code First for a new app and I had all kinds of fun in Excel concatenating() my c# code to seed States and Counties in my app. Rather than force everyone else out there to experience the same joy I did, I through the code into a quick app and posted it on GitHub for you all.

Convert ASP.NET Website to ASP.NET Web Application

Written by rsolberg. Posted in Software Development, Technology

HatM /Free Photos
It wasn’t that many years ago that it seemed like I’d create a new ASP.NET website a few times a week.  Some for rapid prototyping and others for release.  At the time, the applications felt really easy to manage.  That is until they grew and became a beast with all kinds of integration needs. As soon as you start needing to integrate with other systems, databases, applications, etc. the ability to use namespaces and existing components becomes a requirement.  Without it, your code would become completley unmanageable with a complete lack of reuse of components and functions.  I’m not saying that you can’t maintain some good coding practices within an ASP.NET website, but when the app grows and its being integrated with, I absolutely hate code sprawl.   My philosphy on coding is rather simple:  Code it once so that you can reuse it at least twice. Obviously not every code block you write will be reused, but say you have a function to get a contact’s name from your CRM system…  It would seem like this is something you’ll do over and over and over again, so code it once, use it at least twice… With all that said, the need arose to be able to convert these growing ASP.NET websites into ASP.NET Web Applications.  When I got to that point, I was able to find a great resource by Mohamed Meligy on this very topic. Essentially it comes down to a few steps…
  1. Create a new blank solution within Visual Studio
  2. Add a new Web Application Project to the newly created solution
  3. Import existing website files into newly created Web Application project (overwrite files as needed)
  4. Manually add references into the new project that you had in your old website
  5. Once all refernces are added, you likely have many namespace errors.  Create the new namespaces as required.
  6. Now we need to perform a conversion process on the web application project, right click on the new Web Application Project and select “Convert To Web Application”.  This should fix missinging designer.cs or designer.vb.
The above steps will still keep all of your code within a single project in Visual Studio.  Depending on what the application is, does, etc. you may be better off adding a few different projects to seperate database connectivity, data models, and classes that interact with the DB.

ELMAH For Multiple Environments

Written by rsolberg. Posted in All, Technology

Web applications today, especially in medium to larger sized enterprises will be deployed in multiple environments. This allows the development teams to deploy the web application to an environment to verify changes made and that the application functions as expected before shipping it to production. So when you go to use plugins out there such as ELMAH, how should you go about this?  Out of the box, ELMAH allows you to set a single connection string name within your web.config as shown below. So what do you do when you actually have 3 different connection strings for all the environments that your web application exists in?  As it turns out, this is pretty easy to do because ELMAH is open source.  When you download the ELMAH code, you can include it inside your Visual Studio Solution or create a new solution specifically for ELMAH that you can reference from your web application.
If you’re reading this I’m guessing you don’t need help on how to go about doing that.  If you have specific questions, use the contact me page or the comments below.
With the ELMAH code open, look for the SqlErrorLog.cs file and add the code below.  This essentially allows you to set  the connection string property via your application to handle variations… So suppose this was a real world situation where you have a few different connection strings to manage like this: From your Global.asax.cs you can add a line of code to use the correct ELMAH database…
If you’re looking for more information on this, please contact me and I’d be glad to help.

ASP.Net GridView Context Menu

Written by rsolberg. Posted in All, Technology

This post will cover how to add a context menu to a GridView in ASP.Net utilizing jQuery. Once your site is setup to utilize jQuery, you can simply include a new style sheet and script file and get awesome functionality fairly easy! Take a look at this site here to download the required files and their code samples. Mine below shows how I used this on a GridView in ASP.NET…



jQuery Initialization

ASP.Net MVC MarkItUp Rich Text Editor

Written by rsolberg. Posted in All, Technology

MarkItUp identifies itself as being the Universal Markup Editor and from as far as I can tell, this is probably true! It was very easy to integrate the jQuery editor into my new Blog Admin views. I will try to illustrate how I was able to do this below. In addition to the jQuery MarkItUp files, you will also need to download the MarkUp to HTML parser/enhancer of your choice. I used the MarkdownSharp framework which is what the makes of have recently converted to an Open Source project.

Download the MarkItUp Files and MarkDown Sharp

You’ll need to take a look at the MarkItUp Website and download a couple of different files. – markItUp! pack 1.1.6 – Basic MarkDown Set – MarkDownSharp

Include MarkItUp Folder In Your Project

Now that you have the files downloaded, you need to deploy them to your MVC site. I have deployed the MarkItUp folder to my Scripts directory. The MarkItUp folder contains 3 different folders (sets, skins, and templates) and you’ll find a couple of .js files in the root of the folder. Once the MarkItUp folder is in your project, open up the MarkDown file that you downloaded above. You will need to deploy this folder into the Sets folder described above in your project.

LINQ to SQL Where Clause Optional Criteria

Written by rsolberg. Posted in All, Technology

Often times you may allow the users to query your system and you give them the choice of which fields to use in their query. This entry covers how to use optional where criteria within your query and avoid having to write 12 versions of the same query with different where clauses! Let’s take a real example of what I’m talking about… Suppose you have the following basic LINQ query.
  • Product Number – Comes from another table that can be joined to ItemsHeaders.
  • PO Number – a field within the ItemsHeaders table.
  • Order Number – Similar to PO #, just different column.
  • Product Status – Apply if the user selected this from a drop down.In order to accomplish this task, you need to create a couple of extension methods that allow you to apply a where filter if a condition is met.
    New Query!
    I must give special thanks to Andrew Robinson for assisting me with this code and functionality.
  • © Copyright RSolberg, 2003 - 2014. All Rights Reserved