Wednesday, December 23, 2009
Creating custom Server Control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace my_first_control
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server>{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,INamingContainer
{
protected TextBox new_textbox = new TextBox();
protected Button button = new Button();
The Below Strings are Displayed Default in a cs file.Am attached the meaning for the terms below....
[Bindable(true)]----specifies for visual designers whether it is meaningful to bind the property to data
[Category("Appearance")]----specifies how to categorize the property in the visual designer's property browser
[DefaultValue("")]----specifies a default value for the property
[Localizable(true)]----specified as true or false, specifies for visual designers whether it is meaningful to localize the property.
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();//EnsureChildControls method checks if CreateChildControls is already called, and call it if not
return base.Controls;
}
}
protected override void CreateChildControls()
{
//base.CreateChildControls();
Controls.Clear();
new_textbox.ToolTip = "User Created Control";
new_textbox.Text = "NEW CREATED TEXT BOX";
button.Click += new EventHandler(button_Click);
Controls.Add(new_textbox);
Controls.Add(new LiteralControl("
"));
Controls.Add(button);
Controls.Add(new LiteralControl("
"));
}
private void button_Click(object sender, EventArgs e)
{
EnsureChildControls();
new_textbox.Text = "TEXT WORKS";
}
public override void RenderControl(HtmlTextWriter writer)
{
base.RenderControl(writer);
}
protected override void OnInit(EventArgs e)
{
string javascript_code_data = @"";
Page.RegisterClientScriptBlock("my script", javascript_code_data);
base.OnInit(e);
}
}
}
Build the Form as Dll.It Stores in Project Foldrename-->Debug-->Bin-->Filename.dll
add the dll reference to ur page.
We have Two type to Register the Control into our Web From
1. Using Register Namesapace="my_frist_Control" Assembly="My_First_Control" TagPrefix="vijay" with in the tag "<%@Register %>"
2. Add this web Config File.If u Register in web Config File.You need not to Register in Each File.You can use the control in Different File.
system.web
pages
controls
add tagPrefix="mycontrol" namespace="my_first_control" assembly="my_first_control"/
/controls
/pages
/system.web
Then Call the tag name in Web form as
mycontrol:WebCustomControl1 ID="my_control" runat="server"
It Will Show your Control on your Web Form.
Monday, September 14, 2009
Query for creating store procedure for running dynamic table with single Procedure
Declare @table nVarchar(1000)
set @table = 'select * from ' + @table_name
exec(@table)
Run Store Procedure
Exec select_table_dynamic 'table_name'
Monday, September 7, 2009
Coding for Export Sqlserver Data into Excel
Before go in for export,just configure ur Database Driver With the Given Code Below.
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
While Run a below code U must create a xls file in a give path,and specify the header in that file.
Below Code is used to Export Sql Data into Excel Format
OPENROWSET( 'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\testing.xls',
'select fname, lname, email, dateadd, lastchgd, firsttimeuser, active from sql4.ctsi.dbo.users where custno=0913 and active=Y
FROM [Sheet1$]')
select fname, lname, email, dateadd, lastchgd, firsttimeuser, active from sql4.ctsi.dbo.users where custno='0913' and active='Y'
Monday, August 31, 2009
Coding for creating chart using c#.net
Add references of Microsoft office components from com tab.
Include the header file
Using System.OWC;
//Create chartspace object to hola a chart
OWC.ChartSpace draw_chart = new OWC.ChartSpace();
//Add a chart in chartspace
OWC.WCChart chart_obj = draw_chart.Charts.Add(0);
//specify the type of chart to be displayed
chart_obj.Type = OWC.ChartChartTypeEnum.chChartTypeColumnClustered;
//specify the chart legend value,if it is needed.
chart_obj.HasLegend = true;
//set the chart caption on or off and set the caption value of chart.
chart_obj.HasTitle = true;
chart_obj.Title.Caption = "Demo Chart";
//set the caption of x and y axis positions
chart_obj.Axes[0].HasTitle = true;
chart_obj.Axes[0].Title.Caption = "POSITION X";
chart_obj.Axes[1].HasTitle = true;
chart_obj.Axes[1].Title.Caption = "POSITION Y";
//creating a values for a chart
String bar_name = "Line 1";
string x_values = "1" + '\t' + "2" + '\t' + "3";
string y_values = "1" + '\t' + "2" + '\t' + "3";
//add the seriescollection in chart chart object
chart_obj.SeriesCollection.Add(0);
//Binding the chart values in seriescollection array.
chart_obj.SeriesCollection[0].SetData(OWC.ChartDimensionsEnum.chDimSeriesNames, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, bar_name);
chart_obj.SeriesCollection[0].SetData(OWC.ChartDimensionsEnum.chDimCategories, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, x_values);
chart_obj.SeriesCollection[0].SetData(OWC.ChartDimensionsEnum.chDimValues, (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, y_values);
//specify the chart export path.
string chart_path = "chart.gif";
draw_chart.ExportPicture(chart_path, "gif", 500, 500);
//chart file name to be displayed
string gif_file_path = "chart.gif";
//binding the filename into a image tag.
string img_tag="include image tag here with file source name of chart file name mentioned above";
//Add a imagetage into a placedholder to view the chart
chart_container.Controls.Add(new LiteralControl(img_tag));
Thursday, August 27, 2009
Coding for Getting Client System Name
Friday, August 21, 2009
Stored Procedure for login count and update the count in a table
as
declare @result int
begin
if(EXISTS(select * from table_check where username=@username and pass_word=@pass_word))
begin
Set @result=(select access from table_check where username=@username and pass_word=@pass_word)
set @result=@result+1
update table_check set access=@result where username=@username and pass_word=@pass_word
end
else
begin
set @result=0
update table_check set access=@result where username=@username and pass_word=@pass_word
end
begin
select * from table_check
end
end
Thursday, July 30, 2009
Create New Xml File And Update values of the attributs in that XMl File
Creating New XmlFile
XmlTextWriter xml_writer = new XmlTextWriter(Server.MapPath(path), null);
xml_writer.WriteStartDocument();
xml_writer.WriteRaw("");
xml_writer.WriteStartElement("Login_Details");
xml_writer.WriteEndElement();
xml_writer.WriteEndDocument();
xml_writer.Close();
For Updating Attributes Value OF Xml
XmlDocument xml_Doc = new XmlDocument();
xml_Doc.Load(Server.MapPath(path));
foreach (XmlNode node in xml_node)
{
if (node.Attributes[0].InnerText.ToString()=="Test")
{
node.Attributes[0].InnerText = "Text_Modified";
}
}
xml_Doc.Save(Server.MapPath(path));
Coding for Checking User Authentication with XML and Create login Details as XML File
XML Files
Create Xml File then use the below code to access.
C# Codings
int i, j;
string users_pass = string.Empty;
string users_fail = string.Empty;
XmlDocument xml_document = new XmlDocument();
xml_document.Load(Server.MapPath("Login_Details.xml"));
XmlNodeList node_list = xml_document.GetElementsByTagName("username");
for ( i = 0; i < j =" 0;" user_name="node_list[i].ChildNodes[0].InnerText;" pass_word="node_list[i].ChildNodes[1].InnerText;" pass_count =" pass_count" pass_username =" user_name.ToString();" fail_count =" fail_count">= 1)
{
string date = System.DateTime.Now.ToShortDateString();
string date_format = date.Replace('/', '-');
string path = "Login_info_" + date_format.ToString() + ".XML";
XmlDocument xml_doc = new XmlDocument();
xml_doc.Load(Server.MapPath(path));
XmlNode xml_sel = xml_doc.SelectSingleNode("Login_Details");
XmlElement xml_ele = xml_doc.CreateElement("Login_Info");
xml_ele.SetAttribute("user_login", pass_username.ToString());
xml_sel.AppendChild(xml_ele);
xml_ele.SetAttribute("login_time", System.DateTime.Now.ToString());
xml_sel.AppendChild(xml_ele);
xml_doc.Save(Server.MapPath(path));
Response.Write("System pass :"+pass_username.ToString());
pass_count = 0;
}
else
{
Response.Write("System Fails :"+pass_username.ToString());
fail_count = 0;
}
Wednesday, July 22, 2009
Creating Delegates Using C#.net
Creating Of Deletecates Events
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace delegates
{
///
/// Summary description for Delegates
///
public class Delegates : System.Collections.ArrayList
{
public event System.EventHandler changed;
protected virtual void Onchanged(System.EventArgs e)
{
if (changed != null)
{
changed(this, e);
}
}
public override int Add(object value)
{
int i = base.Add(value);
Onchanged(System.EventArgs.Empty);
return i;
}
public Delegates()
{
//
// TODO: Add constructor logic here
//
}
}
}
Creation Of EventHander and Fucntions
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// Summary description for delegates_list
///
///
using delegates;
namespace delegates_list_pro
{
public class delegates_list
{
private Delegates list1;
public delegates_list(Delegates alist)
{
list1=alist;
list1.changed+=new System.EventHandler(listadded);
}
private void listadded(object sender,EventArgs e)
{
System.Windows.Forms.MessageBox.Show("WELCOME");
}
public void Detach()
{
list1.changed-=new System.EventHandler(listadded);
list1=null;
}
public delegates_list()
{
//
// TODO: Add constructor logic here
//
}
}
}
Calling Detlegates and its event handlers from the main program
using delegates;
using delegates_list_pro;
Delegates dele = new Delegates();
delegates_list listener = new delegates_list(dele);
dele.Add("Welcome");
dele.Clear();
listener.Detach();
Thursday, July 2, 2009
Coding for Creating a Window Snap Shot Using C#.net
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
//file name is created based on a time
File_name.Text = System.DateTime.Now.ToShortTimeString();
string file_name = File_name.Text.Replace(':', '-');
Bitmap image = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image); graphics.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size, System.Drawing.CopyPixelOperation.SourceCopy);
image.Save("C:/temp/" + file_name.ToString()+".jpg");
Note:
IF You want to take a snap shot for particualr timer interval, just added a meta tag inside head tag
meta http-equiv="refresh" content="60"
60 refers the page refreshing time in a seconds..
Tuesday, June 30, 2009
Coding for Google Search Engine using Javascript
For More Information View this link
http://code.google.com/apis/ajaxsearch/documentation/#AJAX_Loader
Monday, June 15, 2009
Friday, May 15, 2009
Thursday, May 14, 2009
coding for creating video file as ur own using SMIL Concept
use above coding to perform the task.
Before Getting into Coding, try to know abt this smil coding.
This coding run only in Apple's Quicktime player, Windows Media Player, and RealNetworks RealPlayer support SMIL.
Before You run this code, install one of the above software.
Save the file with the extension filename.smil
Run the program thru players mention above
Wednesday, April 22, 2009
Coding for Export Gridview Data into Excel format
Response.AddHeader("content-disposition", "attachment;filename=C:\\temp\\vijay.xls");//if u want to Export into Document replace vijay.xls with vijay.doc
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vijay.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
Note:
This method is used to Perform the rendercontrol event.
Add the below function with the coding
public override void VerifyRenderingInServerForm(Control control)
{
}
Thursday, March 26, 2009
Coding for changing Image display while Hover using Jquery
$('#div_menu a').animate({"opacity": .7 });
$('#div_menu a').hover(function() {
$(this).stop().animate({ "opacity": 3 });
},
function() {
$(this).stop().animate({ "opacity": .5 });
});
});
$(function() {
$('#div_tools img').animate({"opacity": .5 });
$('#div_tools img').hover(function() {
$(this).stop().animate({ "opacity": 1 });
},
function() {
$(this).stop().animate({ "opacity": .5 });
});
});
Coding for open a document file using javascript
var fso=new ActiveXObject("Word.Application");
fso.Documents.Open(open_path);
fso.Visible=true;
fso.close();
coding for reading text from file in javascript
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = fso.GetFolder("C:\\ctsi\\profile");
var fsoo=new Enumerator(folderObj.Files);
for(i=0;!fsoo.atEnd();fsoo.moveNext())
{
var filename=fsoo.item().name;
}
Tuesday, March 24, 2009
coding for Banner Animation in Jquery
timer="";
$(document).ready(function(){
});
function image()
{
if($("#slideshow").html()!="Stop")
{
$("#slideshow").html("Stop");
timer=window.setInterval("slideshow()",3000);
}
else
{
$("#slideshow").html("Slideshow");
window.clearInterval(timer);
}
}
function slideshow()
{
if(imgc<11)
{
$("#img").fadeOut({complete:function(){$(this).attr("src","./images/image"+imgc+".jpg").fadeIn();}});
imgc++;
}
else
{
imgc=1;
$("#img").fadeOut({complete:function(){$(this).attr("src","./images/image"+imgc+".jpg").fadeIn();}});
}
}
Thursday, March 5, 2009
Accessing Tables from AS400 using C#.Net
using IBM.Data.DB2.iSeries;
iDB2Connection connection_string = new iDB2Connection("DataSource=server_name;UserId=user_name;Password=password");
string select_query="select * from sample";
connection_string.Open();
iDB2DataAdapter Data_Adapter = new iDB2DataAdapter(select_query,connection_string);
DataSet Data_set = new DataSet();
Data_Adapter.Fill(Data_set);
GridView2.DataSource = Data_set;
GridView2.DataBind();
Writing,Reading,Deleting the Files with Javascript
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fso1 = new ActiveXObject("Scripting.FileSystemObject");
var filename=document.getElementById('emp_name').value;
var file_path="c:\\vijay\\"+filename+".txt";var image_path="c:\\vijay\\"+filename+"_img.txt";
if(fso.FileExists(file_path) && fso1.FileExists(image_path))
{
alert('Employee Record Found');
}
else
{
var file_details = fso.CreateTextFile(file_path, true);
var image_details = fso1.CreateTextFile(image_path, true);
var fname=document.getElementById('fname').value;
var lname=document.getElementById('lname').value;
var pic=document.getElementById('pic_file').value;
document.getElementById('img').src=pic;
image_details.writeLine(document.getElementById('pic_file').value);
file_details.WriteLine("FIRST NAME :"+fname);
file_details.WriteLine("LAST NAME :"+lname);
file_details.Close();
}}
function readfile()
{
var filename=document.getElementById('emp_show').value;
var strContents,img_cont; strContents = "";
img_cont="";
var strFileName="c:\\vijay\\"+filename+".txt";
var img_filename="c:\\vijay\\"+filename+"_img.txt";
Fileobject = new ActiveXObject("Scripting.FileSystemObject");
Fileobject1=new ActiveXObject("Scripting.FileSystemObject");
if (Fileobject.FileExists(strFileName) && Fileobject1.FileExists(img_filename))
{
strContents = Fileobject.OpenTextFile(strFileName, 1).ReadAll();
document.getElementById('t1').value=strContents;
img_cont=Fileobject1.OpenTextFile(img_filename, 1).ReadAll();
document.getElementById('img2').src=img_cont;
}
else
{
alert('Employee Name Not found');
}}
function del_emp()
{
var filename=document.getElementById('del_emp').value;
var strFileName="c:\\vijay\\"+filename+".txt";
var img_filename="c:\\vijay\\"+filename+"_img.txt";
fileobj=new ActiveXObject("Scripting.FileSystemObject");
fileobj_img=new ActiveXObject("Scripting.FileSystemObject");
file_value=fileobj.GetFile(strFileName);
file_img_value=fileobj.GetFile(img_filename);
file_value.Delete();
file_img_value.Delete();
alert('File Deleted');
}
Thursday, February 26, 2009
Run Your Web page from Remote Desktop
1. sql Connection string as
Data Source=server_name;Initial Catalog=Database_name;User ID=username;Password=password"
Note:
No need to write like below
Data Source=server_name;Initial Catalog=Database_name;Integrated Security=True;User ID=username;Password=password"
if u run ur page from remote desktop or from ur local system with above sql connection string. The Following Error Will Display
System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
Before Going to run ur web page from remote desktop, first configure ur web folder by iis.
1. start--->control panel--->Administrative Tools---> Internet Information services, double click the icon to open iis.
2.Expand ur local computer name like (vijay(local computer)) , it displays
2.1 Website
2.2 Default SMTP Virtual Server
3. Expand Website option, Default web site option apper, expand Default web site too.
4.It shows the list of Webpage in form of folders.
5.select ur own folder. Right Click and select properties option, in that create virtual directory,just click create button in Application setting segement.
6.select Directory Security Tab---> click edit button
7.Check anonymous access checkbox and Allow iis to control password, and also check Integrate window Authentication.
8. then click ok to finish the process.
We can run our application in two ways
1. From local system with domain or system name
2. From Remote Desktop
From local system, with Domain name
open IE and type the path like below
http://system_name/foldername/Default.aspx (or)
http://localhost/foldername/Default.aspx
From Remote Desktop
http://system_name/foldername/Default.aspx
Friday, February 6, 2009
Coding for displaying details of OnBoard
C#.net Code
ManagementObjectSearcher on_board_details = new ManagementObjectSearcher("root\\CIMV2", "select * from Win32_OnBoardDevice");
{
Response.Write("DESCRIPTION : "+board_details["Description"].ToString()+"
"); Response.Write("DEVICE TYPE : "+board_details["DeviceType"].ToString() + "
"); Response.Write("TAG : "+board_details["Tag"].ToString() + "
"); Response.Write("ENABLED :"+board_details["Enabled"].ToString()+"
"); Response.Write("--------------------------------
");
}
}
JavaScrip Code
function hard_ware()
{
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_OnBoardDevice");
var e = new Enumerator (properties);
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
document.write( p.Description);
document.write(p.DeviceType );
document.write( p.Enabled );
document.write( p.Tag );
}
}
Coding for displaying details of VGA Card
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_VideoController");
foreach (ManagementObject management_object in searcher.Get() )
{
Response.Write( management_object ["Name"].ToString());
Response.Write(management_object["VideoProcessor"].ToString());
Response.Write(management_object["VideoModeDescription"].ToString());
Response.Write(management_object["AdapterRAM"].ToString());
}
Coding for generating text file about desktop details
ManagementObjectSearcher objMOS = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Desktop ");
foreach (ManagementObject objManagemnet in objMOS.Get())
{
try
{
using(StreamWriter objStreamWriter = new StreamWriter(@"C:\DesktopDetails.txt"))
{
objStreamWriter.WriteLine("======================================================================");
objStreamWriter.WriteLine(" DeskTop Details "); objStreamWriter.WriteLine("======================================================================"); objStreamWriter.WriteLine("BorderWidth :" + Convert.ToString(objManagemnet.GetPropertyValue("BorderWidth")));
objStreamWriter.WriteLine("Caption :" + Convert.ToString(objManagemnet.GetPropertyValue("Caption")));
objStreamWriter.WriteLine("Description :" + Convert.ToString(objManagemnet.GetPropertyValue("Description")));
objStreamWriter.WriteLine("IconSpacing :" + Convert.ToString(objManagemnet.GetPropertyValue("IconSpacing")));
objStreamWriter.WriteLine("IconTitleFaceName :" + Convert.ToString(objManagemnet.GetPropertyValue("IconTitleFaceName"))); objStreamWriter.WriteLine("Name :" + Convert.ToString(objManagemnet.GetPropertyValue("Name")));
objStreamWriter.WriteLine("ScreenSaverActive :" + Convert.ToString(objManagemnet.GetPropertyValue("ScreenSaverActive"))); objStreamWriter.WriteLine("ScreenSaverExecutable :" + Convert.ToString(objManagemnet.GetPropertyValue("ScreenSaverExecutable"))); objStreamWriter.WriteLine("ScreenSaverSecure :" + Convert.ToString(objManagemnet.GetPropertyValue("ScreenSaverSecure"))); objStreamWriter.WriteLine("ScreenSaverTimeout :" + Convert.ToString(objManagemnet.GetPropertyValue("ScreenSaverTimeout"))); objStreamWriter.WriteLine("SettingID :" + Convert.ToString(objManagemnet.GetPropertyValue("SettingID")));
objStreamWriter.WriteLine("Wallpaper :" + Convert.ToString(objManagemnet.GetPropertyValue("Wallpaper")));
objStreamWriter.WriteLine("WallpaperStretched :" + Convert.ToString(objManagemnet.GetPropertyValue("WallpaperStretched"))); objStreamWriter.WriteLine("WallpaperTiled :" + Convert.ToString(objManagemnet.GetPropertyValue("WallpaperTiled")));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
Monday, January 19, 2009
calling external js file from another external js file
function one()
{
alert('wroked');
var link_new=document.createElement('script');
link_new_script.src="second.js";
document.body.appendChild(link_new_script);
two();
}
second.js
function two()
{
alert('working');
}
Friday, January 9, 2009
Dictionary Object
using System.Collections.Generic;
Dictionary
myvalue.Add("First Name","VIJAY");
myvalue.Add("Second Name","ANANDH");
foreach (KeyValuePair
{
if (value.Key == "First Name")
{
Response.Write(value.Value.ToString());
}
}