Friday, January 28, 2011

Asp.net Query string how To Transfer File Location

Following Code will help, who want transfer FileLocation
Like (C:\\manikandan\\resume.doc) one page To another page Using Querystring


Sample Code:=
=============

Parent Page:

String fileFullPath=Server.UrlEncode(C:\\manikandan\\resume.doc);
Response.Redirect(..\Sample.aspx?Loc=fileFullPath);



Child Page:
=============

string FileLocation = string.Empty;

if (!string.IsNullOrEmpty(Server.UrlDecode(Request.QueryString["Loc"].ToString())))
{
FileLocation = Request.QueryString["Loc"].ToString();
}

Thanks ,Happy Coding

Monday, January 24, 2011

c# read value from registry

Hi Guys

Following Code will help for how to read values from registry.

RegistryKey regKeyAppRootforET = Registry.LocalMachine.OpenSubKey("SOFTWARE\\YourApplicationName\\KeyName");
if (regKeyAppRootforET != null)
{
if (regKeyAppRootforET.GetValue("KeyName") != null)
{
registryValue = regKeyAppRootforET.GetValue("stringorbinaryKey").ToString();
}
}

Friday, January 21, 2011

Javascript Tips

1)How To Reload the Parent Page Using Javascript

top.location.reload(true);

2)How To Create New Line in Javascript

using "\\n"

sample

alert('sample First Line\\n test')

Using C# Start/Stop Sql Server Services

Following Code will help for starting and stoping Sql Server Services using C#
Code

Sample Code:

ServiceController service = new ServiceController("MSSQL$SQLEXPRESS");//Check sqlexpress service running.
//Sql Serverservice how to stop
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
service.Refresh();
}
//Sql Serverservice how to start
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
}
}

Thursday, January 13, 2011

asp.net ajaxtoolkit modalpopupextender open server side and cleint Side

Following code will help for how to open ajaxtoolkit modalpopupextender

how it can open via server side code (c#) or cleient Side code

javascript
==========
var launch = false;
function launchModal() {
launch = true;
}

function pageLoad() {
if (launch) {
$find("modalpopupextender client id need to pass here").show();
}
}

Client Side
============

OnClientClick="launchModal()"

serverside:=
============

Following code need to write in any button control click event

ClientScript.RegisterStartupScript(this.GetType(), "key", "launchModal();", true);

Using Javascript Read /Write Cookies

Following Code Will help For Reading And Writing cookie

sample code
============


How To Create
createCookie("slidingpane", "dock", 1);
How To Read
var pane = readCookie("slidingpane")



Ref Function

function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name, "", -1);
}

Tuesday, January 11, 2011

JavaScript get Browser height and width and Set into Div

This Article will help for following

1) how To get all Browser Height and Width
2) Dynamically change the div height and width based on browser height and width
3) get the Browser Name

Sample Javascript File
=======================

function() {

var frame = document.getElementById("main");
var htmlheight = document.body.parentNode.scrollHeight;
var windowheight = window.innerHeight;

if (whichBrs() == "Internet Explorer") {
if (htmlheight < windowheight)
{ frame.style.height = windowheight - 150 + "px"; }
else { frame.style.height = htmlheight - 150 + "px"; }

}
else {

if (htmlheight < windowheight) {
frame.style.height = windowheight - 150 + "px";


}
else {
frame.style.height = htmlheight - 150 + "px";

}

}

}




function whichBrs() {
var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0, agt.indexOf('\/'));
}
else return 'Netscape';
} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0, agt.indexOf(' '));
else return navigator.userAgent;
}

Monday, January 10, 2011

Asp.net ReportViewer how to clear if no records found

asp.net report viewer, if initially load all records then if you are changing the filter and your result returns no records means you can see what you got last result it will maintain in report viewer how you can clear,following sample code will help

Sample code :
------------------

Reportviewer1.Reset();

REportviewer1.LocalReport.Refresh();

Asp.net Gridview Page Size Increase Dynamically

Asp.net Run time How We can increase page size dynamically using Gridview PageSizeChangeEventArgs event we can achieve the dynamic page Size , following code will explain


Sample Code:
protected void gv1_PageSizeChange(object sender, PageSizeChangeEventArgs e)

{

gv1.PageSize= e.NewPageSize;

gv1.PageIndex = 0;

BindGrid();

}

asp.net using Crystal report opening pdf inside the web page

Following code will explain asp.net without asking open prompt ,automatically open the pdf file inside aspx

sample Code:
=============


public class WebForm1 : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Web.UI.WebControls.Button Button1;
private CrystalReport1 report = new CrystalReport1();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.Visible = true;
}





-

private void Button1_Click(object sender, System.EventArgs e)
{
MemoryStream oStream; // using System.IO
oStream = (MemoryStream)
report.ExportToStream(
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();
}

Sql Server Get table data (.csv) excuting bat file

How To get sql server Table all records in Csv file by excuting .bat file in Client machine

sample Bat file

1)Open Notepad

2)SQLCMD -S .\SQLEXPRESS -d DatabaseName -E -Q "select * from tableName" -o "FileName.csv" -h-1 -s"," -w 700

3)save as .bat File

Sunday, January 9, 2011

Export Excel From DataGrid using C#

Hi Guys.,
Using c# we need to Export To Excel from datagrid .Following Code will help For you


sample Code:

// create the DataGrid and perform the databinding
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;

DataSet ds = new DataSet();
ds.ReadXml("File Location");
grid.DataSource = ds.Tables[0];
//grid.DataMember = data.Stats.TableName;

grid.DataBind();

// render the DataGrid control to a file
using(StreamWriter sw = new StreamWriter(textBox1.Text))
{
using(HtmlTextWriter hw = new HtmlTextWriter(sw))
{
grid.RenderControl(hw);
}
}
}

Monday, January 3, 2011

usage of Global.axax in asp.net

Following Example will help for maintaining web application

Sample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Diagnostics;

namespace DemoaboutGloabalasax
{
public class Global : System.Web.HttpApplication
{
// int visTeedCount = 0;
///
/// The Application Started it will fire
/// When the iis Start at the time it will fire
///

///
///
protected void Application_Start(object sender, EventArgs e)
{
EventLog.WriteEntry("Sample Application", "Application Started!", EventLogEntryType.Information);

}

protected void Session_Start(object sender, EventArgs e)
{
//visTedCount = visTedCount + visTedCount;
}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
///need to validate Active Directory User Details here
///
}

///
/// This Event Will fire When the application close
/// Ex: iisreset it will fire
///

///
///
protected void Application_End(object sender, EventArgs e)
{

EventLog.WriteEntry("Sample Application", "Application End at" + DateTime.Now.ToString() + "!", EventLogEntryType.Error);

}
}
}

now You can See all the details about your website in your web server using Event Viewer

1)when the Application Started(iis Started)
2)when the Application Stoped/Restarted(iis Reset)
3)what are the error's occurred in application at what time