Tag Archives: visual studio

Visual Studio Runtime Interop Exception

Recently I was working on a Project in Visual Studio 2008 that has some Web Services in it. Every time I opened the project I would get the error:

System.Runtime.InteropServices.COMException

According to a blog post by Marocanu2001, he was receiving this error because he did not have IIS installed.  However in my case this was not the issue. In my case it was because I was running Visual Studio in limited user mode, and not as an administrator. Without Administration rights, when Visual Studio tries to configure the web services in IIS it will throw this exception.

The solution in short:

  • Make sure IIS is installed on your machine

Make sure Visual Studio is run in Administrative mode. (Right-click “Run as Administrator”)

 

Hope this works for you as well. Happy coding!

Post-Processing SSRS Reports using OfficeWriter in .NET

Using OfficeWriter‘s integration with SSRS in conjunction with the Designer is typically a straightforward process with no programmatic manipulation of the reports. A developer designs the report in Visual Studio BIDS, opens the .rdl using the Designer, designs the template in Word/Excel, and publishes the report. The report is then rendered inside the Report Manager using the custom OfficeWriter export option. However, there are times that situations call for post-processing the report programmatically and that’s where the ExcelApplication and WordApplication objects come in. Accessing and rendering the reports through the SSRS API is straightforward and the resulting byte array can be turned into a MemoryStream and passed to OfficeWriter.

Adding the SSRS Web Service

The first step necessary to tapping into the SSRS API is to add the Report Execution Service to your web references inside of Visual Studio. The URL for the web service is likely along the lines of *http://localhost/reportserver/reportexecution2005.asmx*, where localhost/reportserver is the hostname and virtual directory of the SSRS server. Note that this is for SQL Server 2008, despite the 2005. This web service is located in the directory C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer in the example instance I am using. Continue reading Post-Processing SSRS Reports using OfficeWriter in .NET

Spamming Made Easy in ASP.NET

Receiving an auto-generated email is often unpleasant, but when deployed correctly, they can be useful for both customers and companies. C# and SQL make it easy to grab information from a database and send customized emails with little effort.

Step one: grab the data.

Before sending emails, information from the database, like email addresses, needs to be collected by a query. A SQL query is just a string that asks a database for a specific table, but users should be able to dynamically change it depending on their needs.  As such, certain lines need to be flexible.  In the past, I had used string formatting to insert text into the query, which looks like the following:

string text = "I ilke {0} more than {1}, honestly";
text = string.Format(text,"dogs",cats");

How to create a web part containing ASP.NET AJAX-enabled user control in SharePoint 2010

There are existing guides to creating a web part that hosts a user control and others on creating an ASP.NET AJAX-enabled web part. Here I’ll discuss how to create a web part that combines both features. With the user control, you can perform complex layout more easily using the visual designer. And of course, with ASP.NET AJAX you can eliminate full-page postbacks and provide users with a smoother browsing experience.

The walkthrough includes a SoftArtisans.Tutorial.AjaxWebPart for SharePoint 2010 (it can be made to work for SharePoint 2007 with little modification).

SharePoint and ASP.NET AJAX
With SharePoint 2007, the first step would be to configure SharePoint to use ASP.NET AJAX. Fortunately, SharePoint 2010 is already enabled for ASP.NET AJAX, so you can avoid performing error-prone surgery on Web.config.

Step 1: Creating the project

While there are SharePoint project templates, I prefer to use a basic project template for the maximum control and flexibility. It is also more instructive to delve into the nuts and bolts rather than have everything generated for you. Continue reading How to create a web part containing ASP.NET AJAX-enabled user control in SharePoint 2010

How to Assign ASP.NET Development Server to a Specific Port

Recently I was working writing a .NET web service as well as a client application to access this web service. I like to continually test throughout my development, and I noticed that this time, the .NET development server continued to switch ports every time I ran my application. This forced me to change my URL in my client app each time I ran the application as well. To resolve this issue I set the development server to have a static port instead of a dynamic port. Here’s how to do it: In Visual Studio 2008 if you’re using a web application project, right click the project and select properties. You will see the following web tab:

 

 

 

 

 

 

 

There you can set the specific port. In my case I set it to port 8080, but you can set it to anything you would like.

 

System.BadImageFormatException on a 64-bit Machine

The other day, one of our customers was switching over to 64-bit development machines, and encountered the following issue:

System.BadImageFormatException:

Could not load file or assembly ‘(assembly name)’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

The likely reason is that you (or in this instance, our customer) are trying to load a 32-bit assembly into a 64-bit application. This can happen when you have the Any CPU platform selected.

Solution:

If your scenario sounds like the one I described, try setting your application to run in x86 mode. In Visual Studio this can be done by going to Build -> Configuration Manager…

…and setting the Platform to be x86.

SharePoint 2010 Development: Getting Started


[Image via Tihomir Ignatov]

Setting up a SharePoint Development Server

Recently I wanted to start some SharePoint 2010 development, and taking Microsoft’s recommendation that developing for SharePoint be conducted on a machine that already has it installed, I set out to create development-optimized SharePoint environment.

One of the greatest tools I came across was the SharePoint 2010 Easy Setup Script. The script is a set of Windows PowerShell scripts that install and configure all the pre-requisites and products to get you developing for SharePoint in no time.

Running these scripts will install evaluation versions of: Continue reading SharePoint 2010 Development: Getting Started

Adding a View When Provisioning a Custom List

When creating a custom list, you need to provide a list definition in the form of a schema.xml file. Rather than creating a schema.xml file from scratch, a recommended approach is to copy an existing list definition. The out-of-the-box SharePoint custom list is a good starting point as it provides the barest minimum of features required. Armed with a stock list definition, you need to modify it for the list you want to create. If you want to use a specific content type, you can specify it in the <ContentTypes> section. You need to specify the columns of the list in the <Fields> section. Finally, you will want to modify the view definition to specify the columns to be included in the view.

Modifying an existing list definition is a quick way to create a custom list. Often, however, you will want to have more control over the view definition other than what fields are included in it. The view definition is the largest section in the schema.xml and can be rather daunting. Here is where SharePoint Manager comes in. Continue reading Adding a View When Provisioning a Custom List

Adding Web Reference to SSRS 2008 in Visual Studio

To add a reference to SSRS 2005 in Visual Studio, you’d specify the URL to the Web Service definition file, for example
http://server/ReportServer/ReportService2005.asmx or equivalently http://server/ReportServer/ReportService2005.asmx?wsdl. You can use a shorter alternate URL, http://server/ReportServer/ReportService.asmx. If you open these URLs in a Web browser, you’d be able to view the content of the ASMX file.

With SSRS 2008, I’d expect to use the same URLs, replacing 2005 with 2008 where applicable. Alas, it doesn’t work that way. If you browse to http://server/ReportServer/ReportService2008.asmx, you’d get a directory listing rather than the expected Web service definition. A quick check of the MSRS10.MSSQLSERVER\Reporting Services\ReportServer directory reveals that the only relevant Web service definition file is ReportService2005.asmx. Further, the ReportService.asmx file has been inexplicably removed. Continue reading Adding Web Reference to SSRS 2008 in Visual Studio