For .net 4.0 if you get the above error you have to add
<httpRuntime requestValidationMode="2.0" />
Inside the <system.web> tags and
ValidateRequest="false" in <Page> directive of .aspx page
Tuesday, August 9, 2011
Thursday, June 23, 2011
Oracle cache dependency in asp.net
private DataSet bindCachedData()
{
string sql = "SELECT * FROM np_pucm_refresh_cal";
constr = "user id=NPUSER;data source=PNPSCAL;password=NPUSER;Min Pool
Size=1;Connection Lifetime=0;Connection Timeout=60;Incr Pool
Size=1;Decr Pool Size=1;";
DataSet ds;
ds = (DataSet)Cache.Get("UserTable");
if (ds ==null)
{
lblMsg.Text = "Data fetched from Table";
using (OracleConnection con = new OracleConnection(constr))
{
con.Open();
using (OracleCommand cmd = new OracleCommand(sql, con))
{
OracleDependency dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
dep.OnChange += new OnChangeEventHandler(OnMyNotificaton);
OracleDataAdapter da = new OracleDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
Cache.Insert("UserTable", ds);
}
}
}
else
lblMsg.Text = "Data fetched from Cache";
return ds;
}
public void OnMyNotificaton(object src, OracleNotificationEventArgs arg)
{
DataTable changeDetails = arg.Details;
Cache.Remove("UserTable");
lblMsg.Text = "Data fetched from Table";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
GridView1.DataSource = bindCachedData();
GridView1.DataBind();
}
{
string sql = "SELECT * FROM np_pucm_refresh_cal";
constr = "user id=NPUSER;data source=PNPSCAL;password=NPUSER;Min Pool
Size=1;Connection Lifetime=0;Connection Timeout=60;Incr Pool
Size=1;Decr Pool Size=1;";
DataSet ds;
ds = (DataSet)Cache.Get("UserTable");
if (ds ==null)
{
lblMsg.Text = "Data fetched from Table";
using (OracleConnection con = new OracleConnection(constr))
{
con.Open();
using (OracleCommand cmd = new OracleCommand(sql, con))
{
OracleDependency dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
dep.OnChange += new OnChangeEventHandler(OnMyNotificaton);
OracleDataAdapter da = new OracleDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
Cache.Insert("UserTable", ds);
}
}
}
else
lblMsg.Text = "Data fetched from Cache";
return ds;
}
public void OnMyNotificaton(object src, OracleNotificationEventArgs arg)
{
DataTable changeDetails = arg.Details;
Cache.Remove("UserTable");
lblMsg.Text = "Data fetched from Table";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
GridView1.DataSource = bindCachedData();
GridView1.DataBind();
}
Wednesday, June 15, 2011
Import a div's content into excel using javascript
Call the bellow js function "OnClientClick" event of a button
<script language="javascript" type="text/javascript">
function ABC() {
var strCopy = document.getElementById('calendar').innerHTML;
window.clipboardData.setData("Text", strCopy);
var objExcel = new ActiveXObject("Excel.Application");
objExcel.visible = true;
var objWorkbook = objExcel.Workbooks.Add;
var objWorksheet = objWorkbook.Worksheets(1);
objWorksheet.Paste;
return false;
}
</script>
<script language="javascript" type="text/javascript">
function ABC() {
var strCopy = document.getElementById('calendar').innerHTML;
window.clipboardData.setData("Text", strCopy);
var objExcel = new ActiveXObject("Excel.Application");
objExcel.visible = true;
var objWorkbook = objExcel.Workbooks.Add;
var objWorksheet = objWorkbook.Worksheets(1);
objWorksheet.Paste;
return false;
}
</script>
Sunday, April 10, 2011
Create a Win Form with curved corners
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace SampleFormApplication
{
public partial class Login : Form
{
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect,
int nWidthEllipse,
int nHeightEllipse
);
public Login()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width - 10, Height - 10, 50, 50));
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace SampleFormApplication
{
public partial class Login : Form
{
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect,
int nWidthEllipse,
int nHeightEllipse
);
public Login()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width - 10, Height - 10, 50, 50));
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Wednesday, September 29, 2010
How to call a Web Service from client-side JavaScript using ASP.Net
Today I will describe how to call a Web Service from JavaScript in ASP.Net.
Steps are as follows…
Step 1: First create a new AJAX enabled Web Application.
Step 2: Add new Web Service to the project. Let’s say WebService.asmx
Step 3: To allow this Web Service to be called from script
add the following attribute to the Web Service declaration part:
[System.Web.Script.Services.ScriptService]
Step 4: Now we need a Web Method that we will call from client-side JavaScript. Let us define it like this:
[WebMethod]
public string GetServerResponse(string text)
{
if (text == string.Empty)
throw new Exception("Web Service Exception: Enter some text");
return string.Format("Web Service Success: {0} " , DateTime.Now.ToString());
}
Step 5: Add ScriptManager in our .aspx page.
<form id="form1" runat="server" >
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager >
</form >
Step 6: Add ServiceReference to the Services collection and specify Path to the desired service.
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services >
<asp:ServiceReference Path="~/WebService.asmx" />
</Services >
</asp:ScriptManager >
Step 7: Now create the javascript function as follows
<script language="javascript" type="text/javascript">
function SendRequest() {
var val = document.getElementById('<%= txtName.ClientID %>').value;
WebService.GetServerResponse(val, OnComplete, OnError, OnTimeOut);
return false;
}
function OnComplete(arg)
{
alert(arg);
}
function OnTimeOut(arg)
{
alert("timeOut has occured");
}
function OnError(arg)
{
alert("error has occured: " + arg._message);
}
</script >
Step 8: To call this javascript create a textbox and a button in your aspx Page.
<asp:textbox id="txtName" runat="server" >
</asp:textbox >
<asp:button id="btnCallService" runat="server" text="Call Service" onclientclick="javascript:return SendRequest();" ></asp:button >
Steps are as follows…
Step 1: First create a new AJAX enabled Web Application.
Step 2: Add new Web Service to the project. Let’s say WebService.asmx
Step 3: To allow this Web Service to be called from script
add the following attribute to the Web Service declaration part:
[System.Web.Script.Services.ScriptService]
Step 4: Now we need a Web Method that we will call from client-side JavaScript. Let us define it like this:
[WebMethod]
public string GetServerResponse(string text)
{
if (text == string.Empty)
throw new Exception("Web Service Exception: Enter some text");
return string.Format("Web Service Success: {0} " , DateTime.Now.ToString());
}
Step 5: Add ScriptManager in our .aspx page.
<form id="form1" runat="server" >
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager >
</form >
Step 6: Add ServiceReference to the Services collection and specify Path to the desired service.
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services >
<asp:ServiceReference Path="~/WebService.asmx" />
</Services >
</asp:ScriptManager >
Step 7: Now create the javascript function as follows
<script language="javascript" type="text/javascript">
function SendRequest() {
var val = document.getElementById('<%= txtName.ClientID %>').value;
WebService.GetServerResponse(val, OnComplete, OnError, OnTimeOut);
return false;
}
function OnComplete(arg)
{
alert(arg);
}
function OnTimeOut(arg)
{
alert("timeOut has occured");
}
function OnError(arg)
{
alert("error has occured: " + arg._message);
}
</script >
Step 8: To call this javascript create a textbox and a button in your aspx Page.
<asp:textbox id="txtName" runat="server" >
</asp:textbox >
<asp:button id="btnCallService" runat="server" text="Call Service" onclientclick="javascript:return SendRequest();" ></asp:button >
Sunday, September 5, 2010
How to track if any table is deleted/drop from SQL Server database by user
Today I will post one more interesting thing in sql server database.i.e. How to track if any table is deleted/drop from SQL Server database by user….
use DB_name
CREATE TABLE create_table_log
( create_time datetime
, DB_User nvarchar(100)
, Event_type nvarchar(100)
, TSQL nvarchar(2000));
use Db_name
go
create trigger trig_create_table on database for create_table
as
Declare @data xml
set @data=Eventdata()
Insert into create_table_log values
(getdate(),
@data.value('(/EVENT_INSTANCE/LOGINNAME)[1]','nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/EVENTTYPE)[1]','nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(200)')
)
use DB_name
CREATE TABLE create_table_log
( create_time datetime
, DB_User nvarchar(100)
, Event_type nvarchar(100)
, TSQL nvarchar(2000));
use Db_name
go
create trigger trig_create_table on database for create_table
as
Declare @data xml
set @data=Eventdata()
Insert into create_table_log values
(getdate(),
@data.value('(/EVENT_INSTANCE/LOGINNAME)[1]','nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/EVENTTYPE)[1]','nvarchar(100)'),
@data.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(200)')
)
Saturday, June 26, 2010
Resizing images without loss of quality in .Net
Recently I had faced a problem regarding photos that I had captured using my digicam.
When I capture photo using my cannon digicam, the size of each photo is 2MB or more.
So it is very difficult to upload those photos in web because of their size.
And compress those photos one by one using Microsoft Office Picture Manager is difficult too.
So I wrote some code to resize those photos and to minimize the size without affecting the photo quality.
The code is as follow.........
public void ResizeFromStream(string ImageSrcPath, string ImageSavePath, int MaxSideSize)
{
try
{
int intNewWidth;
int intNewHeight;
Image imgInput = Image.FromFile(ImageSrcPath);
//Determine image format
ImageFormat fmtImageFormat = imgInput.RawFormat;
//get image original width and height
int intOldWidth = imgInput.Width;
int intOldHeight = imgInput.Height;
//determine if landscape or portrait
int intMaxSide;
if (intOldWidth >= intOldHeight)
{
intMaxSide = intOldWidth;
}
else
{
intMaxSide = intOldHeight;
}
if (intMaxSide > MaxSideSize)
{
//set new width and height
double dblCoef = MaxSideSize / (double)intMaxSide;
intNewWidth = Convert.ToInt32(dblCoef * intOldWidth);
intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);
}
else
{
intNewWidth = intOldWidth;
intNewHeight = intOldHeight;
}
//create new bitmap
Bitmap bmpResized = new Bitmap(imgInput, intNewWidth, intNewHeight);
//save bitmap to disk
bmpResized.Save(ImageSavePath, fmtImageFormat);
//release used resources
imgInput.Dispose();
bmpResized.Dispose();
}
catch (Exception ex)
{ }
}
When I capture photo using my cannon digicam, the size of each photo is 2MB or more.
So it is very difficult to upload those photos in web because of their size.
And compress those photos one by one using Microsoft Office Picture Manager is difficult too.
So I wrote some code to resize those photos and to minimize the size without affecting the photo quality.
The code is as follow.........
public void ResizeFromStream(string ImageSrcPath, string ImageSavePath, int MaxSideSize)
{
try
{
int intNewWidth;
int intNewHeight;
Image imgInput = Image.FromFile(ImageSrcPath);
//Determine image format
ImageFormat fmtImageFormat = imgInput.RawFormat;
//get image original width and height
int intOldWidth = imgInput.Width;
int intOldHeight = imgInput.Height;
//determine if landscape or portrait
int intMaxSide;
if (intOldWidth >= intOldHeight)
{
intMaxSide = intOldWidth;
}
else
{
intMaxSide = intOldHeight;
}
if (intMaxSide > MaxSideSize)
{
//set new width and height
double dblCoef = MaxSideSize / (double)intMaxSide;
intNewWidth = Convert.ToInt32(dblCoef * intOldWidth);
intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);
}
else
{
intNewWidth = intOldWidth;
intNewHeight = intOldHeight;
}
//create new bitmap
Bitmap bmpResized = new Bitmap(imgInput, intNewWidth, intNewHeight);
//save bitmap to disk
bmpResized.Save(ImageSavePath, fmtImageFormat);
//release used resources
imgInput.Dispose();
bmpResized.Dispose();
}
catch (Exception ex)
{ }
}
Subscribe to:
Posts (Atom)