Developing a REST Web Service using C# – A walkthrough

REST stands for Representational State Transfer. The term was introduced by Roy Fielding in his doctorial dissertation. REST is an architectural style for designing networked applications. It is an alternate to using complex mechanisms like COBRA, RPC, and SOAP to connect between client and server. REST makes communication between remote computers easy by using the simple HTTP protocol which support for CRUD (Create, Read, Update, and Delete) operations on the server. In a way, our World Wide Web is also based on the REST architecture. In a nutshell, REST is…

Read More

C# Extension Method

An extension method has simplified calling syntax. It represents static methods as instance methods. An extension method uses the this-keyword in its parameter list. It must be located in a static class. Example First, here is a custom extension method defined in a program written in the C# language. Generally, you will want to store your extension method class in a separate source file, such as “ExtensionMethods.cs” in your project. Note:This file should store a static class with public static extension methods. Then: In the rest of your source code,…

Read More

How create a OFT file for HTML?

OFT file is a Outlook Template of an email. If you need to send a newsletter for example, it’s very useful to create this kind of file. The procedure to make a OFT file is very simple: build html file open the file in Internet Exlorer in IE open the menu (don’t use the icon!) File | Send | Page by e-mail Outlook opens a new email with the page click on File | Save As, click dropdown and select Outlook Template (*.oft), save to desired location

Read More

Reading multiple excel sheets with different worksheet names

I would like to know how I can read multiple excel worksheet with different worksheet name in c# and with the used of oledb. I have this existing way to read multiple sheets (but with fixed worksheet name):             DataSet ds = new DataSet();            var excelConnectionString = string.Format(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0”, path);            OleDbConnection connection = new OleDbConnection();            connection.ConnectionString = excelConnectionString;             var i = 1;            while (i <= 4)            {                string query = “SELECT * FROM [Sheet” + i + “$]”;                ds.Clear();                OleDbDataAdapter data = new OleDbDataAdapter(query, connection);                data.Fill(ds);                …

Read More

Download page from web with encoding

Usually you can use WebClient to download a page from web but no always it’s a good way, sometimes the page encode is different. With this code you can download without problems! #region ” Download page “public static string PageDownload(string url){    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);     using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())    {        byte[] buffer;         using (Stream s = resp.GetResponseStream())        {            buffer = ReadStream(s);        }         string pageEncoding = “”;        Encoding e = Encoding.UTF8;        if (resp.ContentEncoding != “”)            pageEncoding = resp.ContentEncoding;        else if (resp.CharacterSet != “”)            pageEncoding = resp.CharacterSet;        else…

Read More

What is the JavaScript Equivalent of print_r in PHP?

What is the JavaScript Equivalent of PHP print_r() function? In other words, how you can “print” a javascript object in a way that’s readable by humans? Code You could use JSON.stringify, as following: The HTML part Let’s create two links for demo: <p><a id=”print_demo” href=”javascript:void(0);”>Print object</a></p><p><a id=”pretty_print_demo” href=”javascript:void(0);”>Pretty Print object</a> The JAVASCRIPT part Remark: I use jQuery to handle events, but you can use plain javascript (if you prefer). <script type=”text/javascript”> $(function() { // create an object var person = new Object(); person.firstname = “John”; person.lastname = “Doe”; person.age =…

Read More

How to Detect Browser (and browser version) using JavaScript

Browser (and browser version) detection is an “all time classic” development requirement. jQuery.browser WAS an excellent solution, but it was removed in jQuery 1.9. Actually, it would be better to try to detect a browser feature instead of browser name itself, where possible. An ideal solution for this is Modernizr (a JavaScript library that detects HTML5 and CSS3 features in the user’s browser). But, if you still need to detect browser and browser version (using javascript), I suggest the following solutions (among many others): Bowser – A Browser detector and…

Read More

Render LocalReport using Microsoft ReportViewer DLL Version 11.0.3366.16

I downloaded the latest Microsoft ReportViewer from the link below and installed it. I want to be able to export (render) my Excel files in xlsx format. I’m referencing version 11.0.3366.16 of the following dll’s in my project… Microsoft.ReportViewer.CommonMicrosoft.ReportViewer.ProcessingObjectModelMicrosoft.ReportViewer.WinForms The download linkhttps://www.microsoft.com/en-us/download/details.aspx?id=35747 When specifying what you want your output to be, instead of sending WORD and EXCEL as the parameters for the output, send WORDOPENXML and EXCELOPENXML for the new office version. To verify what output your version of assemblies support, use <ReportObjec>.LocalReport.ListRenderingExtensions For example:RenderingExtension[] r = reportViewer.LocalReport.ListRenderingExtensions(); The complete…

Read More

Mime type for Microsoft Office 2007-2010

.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template.potx application/vnd.openxmlformats-officedocument.presentationml.template.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation.sldx application/vnd.openxmlformats-officedocument.presentationml.slide.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template.xlam application/vnd.ms-excel.addin.macroEnabled.12.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12

Read More

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to… web.config issue

I have a problem like this on server [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from ‘System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll’. Type B originates from ‘System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘Default’ at location ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll’. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from ‘System.Web.WebPages.Razor, Version=2.0.0.0,…

Read More

IIS rewrite rules

This post describes some of the tips and tricks that one may find useful when solving URL-based problems for their web server or web site. Each tip/trick has a description of a problem and then an example of how it can be solved with IIS 7 URL Rewrite Module. 1. Add or Remove Trailing Slash Many web applications use “virtual URLs” – that is the URLs that do not directly map to the file and directory layout on web server’s file system. An example of such application may be an…

Read More