Selecting nodes with no namespace using XPath in C#

When nodes in an XML document has no prefix at all you would think that they are associated with the default namespace, but apparently this is not the case.

Those nodes are considered not associated with any namespace at all. So to select them using XPath, in the NamespaceManager first add the default namespace with any arbitrary prefix of your choosing but not string.Empty, for example:

namespaceManager.AddNameSpace(“x”, “http://…”);

Here x is just a randomly chosen prefix

Then, you can use XPath to select nodes using the prefix you just added

doc.SelectNodes(“//x:NodeName”, namespaceManager);

I spent 2 hours to figure this out, talk about wasting time.

Consume Web API response in SSRS

Follow the article: http://jaliyaudagedara.blogspot.sg/2015/10/using-aspnet-web-api-as-data-source-for.html

Need to configure the web api service to always return XML data. When configuring the data source, add ?type=xml at the end of the URL.

Note: for SSRS/Report Builder to retrieve the fields, don’t use blank query string, use the following:

<Query>

</Query>

Find /bin folder for SSRS integrated with SharePoint

SharePoint strikes again.

Follow the article http://blogs.catapultsystems.com/aroney/archive/2013/02/11/custom-dlls-with-sql-server-reporting-services-in-sharepoint-integrated-mode/

Normally, you can find the SSRS at C:\Program Files\Microsoft SQL Server\ MSRS10_50.SQLSERVER\Reporting Services\

If you want to find the folder for SSRS integrated with SharePoint, it’s not where it’s usually located but under the /15 hive, C:\Program Files\Common Files\Microsoft Shared\Web Service Extensions\15\Webservices\reporting\bin

Browsing functionality in a referenced binary

Keyword: object browser in Visual Studio

If you are working on a project with some binaries developed by the company previously and you don’t have access to the source code.

Aside from asking your colleague, use Visual Studio’s Object Explorer to browse the API in referenced binaries without the need of the source code.

Cannot bind multiple parameters in Web Api, cannot bind Json parameter

Simple, Web Api 1 doesn’t support multiple parameters.

Also, make sure the route config are correct so that the controller and action can be reached.

To bind Json parameter, use Content-Type: application/json in the request header, make sure the json object is the root object and the model to load from the server user properties instead of fields.

Cannot connect to SQL DB from IIS, connection works from IISExpress

Stackoverflow question/answer: http://stackoverflow.com/questions/20723623/application-cannot-open-sql-connection-when-on-iis

You can either give permission to the app pool from within SQL Server.

Or create a SQL Server user/pass, update the connection string to use User/Pass instead of Integrated Security

Setting up SSL with IIS for development and testing of ASP.NET applications

Note: this will potentially solve the issue when Visual Studio shows the following error upon trying to debug: “Unable to debug the web server… An error occurred on a send.”

The problem can be solved by re-creating and adding a SSL cert to the port 443 binding of the default web application.

 

Follow the following steps:

From IIS, under the local server, open “Server Certificates”. Use an existing cert or create a self-signed cert, give it a name.

Select the Web application(not a virtual directory) that you want to use. Edit the bindings, add a binding for https port 443 and select the certificate you created previously and then save.

Note: when running applications off an existing web application in IIS, make sure to create virtual directories for each app if they are not available, you can do so by going to the project’s properties, under “Using local IIS server”, next to the URL of the app click the button “Create virtual directory”

Saving settings to app.config for C# winforms app

Follow the following stackoverflow question:

http://stackoverflow.com/questions/30572923/read-all-key-values-from-app-config-c-sharp

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

config.AppSettings.Settings.Remove("MySetting");
config.AppSettings.Settings.Add("MySetting", "some value");

config.Save(ConfigurationSaveMode.Modified);