
September 14, 2015 06:02 by
Peter
This is all concerning JSON Parsing in ASP.NET. JSON is a info that for running JavaScript on websites. Now a days , JSON is booming on website.This code focuses on JSON serialization and Deserialization in ASP.NET 4.6. First, open your visual studio and then write the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
/// <summary>
/// JSON Serialization and Deserialization Class
/// </summary>
namespace JsonParsingSample
{
public class ClassJsonHelper
{
/// <summary>
/// JSON Serialization Method
/// </summary>
public static string ToJsonConvertor < T > (T t)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, t);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
//Replace Json Date String
string p = @"\\/Date\((\d+)\+\d+\)\\/";
MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertJsonDateToDateString);
Regex reg = new Regex(p);
jsonString = reg.Replace(jsonString, matchEvaluator);
return jsonString;
}
/// <summary>
/// JSON Deserialization Method
/// </summary>
public static T FromJsonConvertor < T > (string jsonString)
{
//Convert "yyyy-MM-dd HH:mm:ss" String as "\/Date(1319266795390+0800)\/"
string p = @"\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}";
MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertDateStringToJsonDate);
Regex reg = new Regex(p);
jsonString = reg.Replace(jsonString, matchEvaluator);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T) ser.ReadObject(ms);
return obj;
}
/// <summary>
/// Convert Serialization Time /Date(1319266795390+0530) as String
/// </summary>
private static string ConvertJsonDateToDateString(Match m)
{
string result = string.Empty;
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds(long.Parse(m.Groups[1].Value));
dt = dt.ToLocalTime();
result = dt.ToString("yyyy-MM-dd HH:mm:ss");
return result;
}
/// <summary>
/// Convert Date String as Json Time
/// </summary>
private static string ConvertDateStringToJsonDate(Match m)
{
string result = string.Empty;
DateTime dt = DateTime.Parse(m.Groups[0].Value);
dt = dt.ToUniversalTime();
TimeSpan ts = dt - DateTime.Parse("1970-01-01");
result = string.Format("\\/Date({0}+0530)\\/", ts.TotalMilliseconds);
return result;
}
}
}
HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


September 7, 2015 12:32 by
Peter
HostForLIFE.eu was established to cater to an underserved market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu – a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. HostForLIFE.eu proudly announces the availability of the ASP.NET 4.6 hosting in their entire servers environment.

ASP.NET is Microsoft's dynamic website technology, enabling developers to create data-driven websites using the .NET platform and the latest version is 5 with lots of awesome features. ASP.NET 4.6 is a lean .NET stack for building modern web apps. Microsoft built it from the ground up to provide an optimized development framework for apps that are either deployed to the cloud or run on-premises. It consists of modular components with minimal overhead.
According to Microsoft officials, With the .NET Framework 4.6, you'll enjoy better performance with the new 64-bit "RyuJIT" JIT and high DPI support for WPF and Windows Forms. ASP.NET provides HTTP/2 support when running on Windows 10 and has more async task-returning APIs. There are also major updates in Visual Studio 2015 for .NET developers, many of which are built on top of the new Roslyn compiler framework. The .NET languages -- C# 6, F# 4, VB 14 -- have been updated, too.There are many great features in the .NET Framework 4.6. Some of these features, like RyuJIT and the latest GC updates, can provide improvements by just installing the .NET Framework 4.6.
HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt(DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting their ASP.NET 4.6 site on their environment from as just low €3.00/month only.
HostForLIFE.eu is a popular online ASP.NET based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.
HostForLIFE.eu offers the latest European ASP.NET 4.6 hosting installation to all their new and existing customers. The customers can simply deploy their ASP.NET 4.6 website via their world-class Control Panel or conventional FTP tool. HostForLIFE.eu is happy to be offering the most up to date Microsoft services and always had a great appreciation for the products that Microsoft offers.
Further information and the full range of features ASP.NET 4.6 Hosting can be viewed here http://hostforlife.eu/European-ASPNET-46-Hosting

August 10, 2015 11:53 by
Peter
Representational State Transfer (REST) isn't SOAP based Service and it exposing a public API over the internet to handle CRUD operations on information. REST is targeted on accessing named resources through one consistent interface (URL). REST uses these operations and alternative existing options of the HTTP protocol:
From developer's points of view, it's not as easy as handling the object based Module which is supported after we create SOAP URL as reference or create WSDL proxy.
But .NET will have class to deal with JSON restful service. This document will only cover "how to deal JSON response as a Serialized Object for READ/WRITE & convert JSON object into meanful Object".

In order to consumer JSON restful service , we'd like to do follow steps:
- produce the restful request URI.
- Post URI and get the response from “HttpWebResponse” .
- Convert ResponseStreem into Serialized object from “DataContractJsonSerialized” function.
- Get the particular results/items from Serialized Object.
This is very generic function which can be used for any rest service to post and get the response and convert in:
public static object MakeRequest(string requestUrl, object JSONRequest, string JSONmethod, string JSONContentType, Type JSONResponseType) {
try {
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
//WebRequest WR = WebRequest.Create(requestUrl);
string sb = JsonConvert.SerializeObject(JSONRequest);
request.Method = JSONmethod;
// "POST";request.ContentType = JSONContentType; // "application/json";
Byte[] bt = Encoding.UTF8.GetBytes(sb);
Stream st = request.GetRequestStream();
st.Write(bt, 0, bt.Length);
st.Close();
using(HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).", response.StatusCode,
response.StatusDescription));
// DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));// object objResponse = JsonConvert.DeserializeObject();Stream stream1 = response.GetResponseStream();
StreamReader sr = new StreamReader(stream1);
string strsb = sr.ReadToEnd();
object objResponse = JsonConvert.DeserializeObject(strsb, JSONResponseType);
return objResponse;
}
} catch (Exception e) {
Console.WriteLine(e.Message);
return null;
}
}
HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


July 31, 2015 07:43 by
Peter
Hi, In this post let me explain you about how to verify if the remote files exist or not in ASP.NET 5. Sometimes we need to verify if a file exists remotely such as javascript or image file. Suppose you are in server(xxx.com) and you want to check a file in another server(xxxxxx.com) - in this case it will be helpful. And now, write the following code snippet.

Using HTTPWebRequest:
private bool RemoteFileExistsUsingHTTP(string url)
{
try
{
//Creating the HttpWebRequest
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//Returns TURE if the Status code == 200
return (response.StatusCode == HttpStatusCode.OK);
}
catch
{
//Any exception will returns false.
return false;
}
}
Using WebClient:
private bool RemoteFileExistsUsingClient(string url)
{
bool result = false;
using (WebClient client = new WebClient())
{
try
{
Stream stream = client.OpenRead(url);
if (stream != null)
{
result = true;
}
else
{
result = false;
}
}
catch
{
result = false;
}
}
return result;
}
Call Method:
RemoteFileExistsUsingHTTP("http://localhost:16868/JavaScript1.js");
Don't confuse here as a result of it absolutely was implemented in 2 ways. continually use HttpWebRequest class over WebClient because of the following reasons:
1. WebClient internally calls HttpWebRequest
2. HttpWebRequest has a lot of options (credential, method) as compared to Webclient
HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


July 9, 2015 11:42 by
Peter
In this post, I will explain you about how to create QR Code Generator with ASP.NET 5. Though there are several solutions for QR Code generation in ASP.NET 5, all of it needs referring to third party dlls. however there's a really simple alternative through that we can create a QR code generator in ASP.Net within minutes without relating any third party dlls. Let's produce a ASP.Net web application with a text box, image control and Button with the following code
<asp:TextBox runat="server" ID="txtData"></asp:TextBox>
<asp:Button runat="server" ID="btnClickMe" Text="Click Me" OnClick="btnClickMe_Click" />
<br />
<asp:Image runat="server" ID="ImgQrCode" Height="160" Width="160" />

Now, in the button click event, generate the URL for the API with the data entered in the text box and size of the image control and set it to the image control's image URL property. Write the following code:
protected void btnClickMe_Click(object sender, EventArgs e)
{
ImgQrCode.ImageUrl = "https://chart.googleapis.com/chart? cht=qr&chl=" + WebUtility.HtmlEncode(txtData.Text) + "&choe=UTF-8&chs=" + ImgQrCode.Height.ToString().Replace("px", "") + "x" + ImgQrCode.Width.ToString().Replace("px", "");
}
And here is the output:

I hope this tutorial works for you!
HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


July 3, 2015 11:33 by
Peter
In this example, I will tell you how to Bind the empty Grid with Header and Footer when no data in GridView and binding the grid using XML data and performing CURD operations on XML file.

First create a new project one your Visual Basic Studio and then write the following code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace OvidMDSample
{
public partial class Home: System.Web.UI.Page
{
private const string xmlFilePath = "~/XML/HiddenPagesList.xml";
public string domainUrl = HttpContext.Current.Request.Url.Authority;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindHiddenPages();
}
}
private void BindHiddenPages()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(xmlFilePath));
if (ds != null && ds.HasChanges())
{
grdHiddenPages.DataSource = ds;
grdHiddenPages.DataBind();
}
else
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("PageName");
dt.Columns.Add("Description");
dt.Columns.Add("PageUrl");
dt.Columns.Add("Address");
dt.Rows.Add(0, string.Empty, string.Empty, string.Empty);
grdHiddenPages.DataSource = dt;
grdHiddenPages.DataBind();
grdHiddenPages.Rows[0].Visible = false;
// grdHiddenPages.DataBind();
}
}
}
}
HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


June 30, 2015 08:38 by
Peter
We create some true or false questions so the user can provide their answer and on a button click the solution are going to be saved to a database. Open your Visual Studio and build an empty web site, provide a suitable name (RadioButtonList_demo). In solution explorer you get your empty web site, add a web form and SQL database as in the following

For web Form:
RadioButtonList_demo (your empty website) then right-click then choose Add New Item -> internet type. Name it RadioButtonList_demo.aspx.
For SQL Server database:
RadioButtonList_demo (your empty website) then right-click then choose Add New Item -> SQL Server database. (Add the database within the App_Data_folder.) In Server explorer, click on your database (Database.mdf) then choose Tables ->Add New Table. create the table like this:

This table is for saving the data of the radio button list, I mean in this table we will get the user's answer of true and false questions. Open your RadioButtonList_demo.aspx file from Solution Explorer and start the design of you're application. Here is the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 211px;
}
.style2
{
width: 224px;
}
.style3
{
width: 224px;
font-weight: bold;
text-decoration: underline;
}
.style4
{
width: 211px;
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table style="width:100%;">
<tr>
<td class="style4">
</td>
<td class="style3">
Please Answer these Questions</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label7" runat="server"
Text="Is Earth is the only planet in the universe??"></asp:Label>
</td>
<td class="style2">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" DataTextField="ans"
DataValueField="ans">
<asp:ListItem>True</asp:ListItem>
<asp:ListItem>False</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Is Moon is our Natural Satellite?"></asp:Label>
</td>
<td class="style2">
<asp:RadioButtonList ID="RadioButtonList2" runat="server" DataTextField="ans1"
DataValueField="ans1">
<asp:ListItem>True</asp:ListItem>
<asp:ListItem>False</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server"
Text="Earth is having Rings like Saturn have ?"></asp:Label>
</td>
<td class="style2">
<asp:RadioButtonList ID="RadioButtonList3" runat="server" DataTextField="ans2"
DataValueField="ans2">
<asp:ListItem>True</asp:ListItem>
<asp:ListItem>False</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit your answer" />
</td>
<td>
<asp:Label ID="lbmsg" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
And here is the output:

Finally open your RadioButtonList_demo.aspx.cs file to write the code, for making the list box like we assume. Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("insert into tbl_data (ans,ans1,ans2) values (@ans,@ans1,@ans2)", con);
cmd.Parameters.AddWithValue("ans", RadioButtonList1.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans1", RadioButtonList2.SelectedItem.Text);
cmd.Parameters.AddWithValue("ans2", RadioButtonList3.SelectedItem.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i != 0)
{
lbmsg.Text = "Your Answer Submitted Succesfully";
lbmsg.ForeColor = System.Drawing.Color.ForestGreen;
}
else
{
lbmsg.Text = "Some Problem Occured";
lbmsg.ForeColor = System.Drawing.Color.Red;
}
}
}
Output:


HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.


June 26, 2015 08:48 by
Peter
In this article, I explained how to How to Highlight Dates in Calendar with ASP.NET. First step create new ASP.NET Empty web Application provides it to that means full name. Now, Add new webfrom to your project. Then drag and drop Calendar on your design page. Now. add two properties WeekendDayStyle-BackColor="Yellow", WeekendDayStyle-ForeColor="Black" to your calender control as shown below and run your application.

<asp:Calendar ID="Calendar1" runat="server"
WeekendDayStyle-BackColor="Yellow"
WeekendDayStyle-ForeColor="Green" ></asp:Calendar>
And here is the output:

You can achieve the same by using (OnDayRender event) code as mentioned below. Remove WeekendDayStyle-BackColor="Yellow", WeekendDayStyle-ForeColor="Green" from Calender control.
Here is the .aspx code
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender"></asp:Calendar>
CodeBehind:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsWeekend)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
e.Cell.ForeColor = System.Drawing.Color.Green;
}
}
If you wish to spotlight on 'Monday' write the subsequent code in Calendar1_DayRender event. It highlights the the desired day dates.
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
e.Cell.ForeColor = System.Drawing.Color.Green;
}

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.
