Archive for the ‘ASP.NET’ Category

HTTP Error 404.3 – Not Found The page you are requesting cannot be served because of the extension configuration.

April 21, 2015 Leave a comment

Resolve this MIME issue by adding the extension in web.config

 <compilation debug="true" targetFramework="4.0" />
 <remove fileExtension=".json" />
 <mimeMap fileExtension=".json" mimeType="application/json" />


Categories: ASP.NET Tags: , ,

Ajax call before form submit c#

July 28, 2013 4 comments

Let me share an issue i faced.

I have a textbox with google auto complete plugin.


I need to store the place i typed in, its latitude, longitude in to the database.

So google have the javascript api to get the latitude and longitude, but it should be called before the form button click to store that in Hidden fields(my way), so i can get the values in server side(c#).

I tried the OnClientClick, but the hidden fields are not set with lat and long. The form is always submitting before the result is came from the ajax call :(.

I found a solution.

var geocoder;
function SetLatLng() {
geocoder = new google.maps.Geocoder();
           var address1 = document.getElementById("location1").value;
geocoder.geocode({ 'address': address1 }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
return false;
<asp:Button ID="FirstButton" OnClientClick="SetLatLng(); return false;" runat="server" Text="Click" />
<asp:Button ID="SecondButton" OnClick="buttonSubmit_Click" runat="server" Text="Click" style="display:none" />
<asp:HiddenField ID="HFLat" runat="server" Value="" />
<asp:HiddenField ID="HFLng" runat="server" Value="" />

Make 2 buttons, one for running the javascript, if the value is returned from the ajax call, click the second button programmatically 😛

Happy coding 🙂

Awesome plugin for multiple file upload ajax

July 2, 2013 Leave a comment

Got a simple and nice plugin for uploading multiple files.


Here is my source code

You can see detailed options here :

Happy coding 🙂

Markers on map javascript c#

June 27, 2013 Leave a comment

Sometimes we gets trouble to mix Javascript and C#.
Here is my source to display dynamic markers on google map.

See live here

I called an aspx page to get some places as C# List, and convert the list to Javascript array from the ajax result.
So we can show markers on map using the normal google api functions.


Serialize and Deserialize JSON using JSON.NET

May 22, 2013 Leave a comment

An awesome tool to convert json string to objects and back to json – JSON.NET
Get it from here

   WebClient wc = new WebClient();         
   string jsonStr = wc.DownloadString("http://example/api/GetAllBrandIds.aspx");
   JObject obj = JObject.Parse(jsonStr);
   JToken jt = obj["IdType"];
   BrandSet bs;
   List<BrandSet> list = new List<BrandSet>();
   foreach(JToken j in jt)
   bs = new BrandSet(); 
   bs.ID = Convert.ToInt32((string)(j["Id"]));                
   bs.ImageType = Convert.ToInt32((string)(j["ImageType"]));
  //Serialize back to json
  string jsonStr = JsonConvert.SerializeObject(list);

Happy coding:)

Read Excel file from ASP.NET C#

May 15, 2013 1 comment

Really excited to get a snippet that reads the excel file as database table:)

Sample code below

        string connStrExcel = "";
        if (type.Equals("xlsx"))
          connStrExcel = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=YourExcelFilePath.xlsx;Extended Properties=Excel 12.0";
          connStrExcel = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourExcelFilePath.xls;Extended Properties=Excel 8.0";
        OleDbConnection oledbConn = new OleDbConnection(connStrExcel);
        DataTable tab = new DataTable();

        {   //Open connection
           // Create OleDbCommand object and select data from worksheet Sheet1
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
           // Create new OleDbDataAdapter
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            oleda.SelectCommand = cmd;
            // Fill the DataTable from the data extracted from the worksheet.
        finally             '

Happy Coding:)

Categories: ASP.NET Tags:

Android Push Notification ASP.NET C#

April 23, 2013 2 comments

The below code will send push notification to an android phone using ASP.NET C#



string msg = “Message from ASP.NET”

WebRequest tRequest;

tRequest =


tRequest.Method =


tRequest.ContentType =



string.Format(“Authorization: key={0}”, GoogleAppID));

String collaspeKey = Guid.NewGuid().ToString(“n”);

String postData = string.Format(“registration_id={0}&data.msg={1}&collapse_key={2}”, DeviceID, msg, collaspeKey);

Byte[] byteArray = Encoding.UTF8.GetBytes(postData);

tRequest.ContentLength = byteArray.Length;

Stream dataStream = tRequest.GetRequestStream();

dataStream.Write(byteArray, 0, byteArray.Length);


WebResponse tResponse = tRequest.GetResponse();

dataStream = tResponse.GetResponseStream();

StreamReader tReader = newStreamReader(dataStream);

String sResponseFromServer = tReader.ReadToEnd();