Reference site for Sitecore and Dot NET. Call at +91-9910045174 for any Sitecore corporate trainings and workshops.
Surendra Sharma
Search This Blog
Thursday, May 13, 2010
Get the difference of month between two dates
private static int monthDifference(DateTime startDate, DateTime endDate)
12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month; return Math.Abs(monthsApart);
}
To solve apostrophe problem in where condition of SQL Statement
string
str = "King''s Jalepenos";
str= str.Replace("'","''");
WinCV.exe - viewing the contents of any DOT NET namespace
Memory Management for ASP.NET & making space for C: drive
Create HTML Table in ASP.NET
Table one Table & say Run as a server control. Its Id is “tblIntangiblesInner”
public
void FillIntangibleTable()
{
ArrayList arrList = null;
arrList = (ArrayList)LoadAllIntangibles();
foreach (object
item in arrList)
{
HtmlTableRow theRow = new HtmlTableRow();
HtmlTableCell []theCell = new
HtmlTableCell[2];
theCell[0] = new HtmlTableCell();
theCell[1] = new HtmlTableCell();
theCell[0].Width = "5%";
theCell[1].Width = "95%";
theCell[0].InnerHtml = " ";
theCell[1].InnerHtml = "<a
href=default.aspx?GSIN="+item.ToString()+">"
+ item.ToString() + "</a>";
theRow.Cells.Add(theCell[0]);
theRow.Cells.Add(theCell[1]);
tblIntangiblesInner.Rows.Add(theRow);
}
public
ArrayList LoadAllIntangibles()
{
System.Collections.ArrayList obj = new
System.Collections.ArrayList();
obj.Add("2");
obj.Add("3");
obj.Add("4");
obj.Add("5");
obj.Add("6");
obj.Add("7");
return obj;
Printting a file in .NET
psiPrint.Verb = "print"
psiPrint.WindowStyle = ProcessWindowStyle.Hidden
psiPrint.FileName = "C:\MyFile.pdf"
psiPrint.UseShellExecute = True
System.Diagnostics.Process.Start(psiPrint)
Select CASE Statement in SQL
WHEN 'F' THEN 'Femenino'
END
) AS Sexo
FROM tblDatos
Redirecting User to Login Page After Session Timeouts
Refreshing any page after certain interval
For
refreshing any page after certain interval, you need to use client side script
only. You cant do this in server side, The reason being that the page has been
served to the client, end of request. The web is stateless; until the user
comes back and initiates another request the server can't do anything. So we
need to do this refreshing activity from client side only. There are two ways to
achieve this,
1. Using Window.setTimeout method
2. Using
Using
Window.setTimeout method:
DHTML Window object has a
method called "setTimeout" which evaluates an expression after a specified
number of milliseconds has elapsed. With the help of this method, you can run
the client side script window.location.href="somepage" to redirect page in the
current window. SetTimeout accepts three parameters.
vCode |
Required. Variant that |
||||||
iMilliSeconds |
Required. Integer that |
||||||
sLanguage |
Optional. String that
|
You need to call
this method in body load and start the timer( by calling setTimeout method).
This timer will elapse depending upon the second parameter for this method. When
it is elapsed, it will fire the script which is given as first parameter. So you
need to add this to the body element onload method. For adding client side event
to body tag in asp.net you need to follow this methos.
1. Declare the body tag in
html window as server control by specifing runat attribute and give an id to
that tag.
<body runat="server" id= "body">< /P>< /FONT>
2. In the code behind,
declare this element as htmlgenericcontrol like this.
Protected WithEvents body As
System.Web.UI.HtmlControls.HtmlGenericControl
3. Finally add
the following code in your page_load event handler, this will add the client
side handler for body tag.
body.Attributes.Add("onLoad",
"window.setTimeout(""window.location.href='<somepage>.aspx'"",5000);")
This method will
refresh the page to the specified location after 5 secs. The disadvantage of
this method is, this might not work in some lower end browsers. So you need to
go for other method i.e. by using Meta Tags.
Using
Another way for refreshing the page after certain interval is by using meta tag
- Refresh. This tag specifies a delay in seconds before the browser
automatically reloads the document. Optionally, specifies an alternative URL to
load. Example
<
CONTENT="3;URL=http://www.some.org/some.html">
In ASP.NET, you
can add headers in code behind using this method.
Response.AppendHeader("Refresh", "10;
URL=.aspx")
This method will
reload the current window after interval mentioned in the second parameter to
the page which is mentioned as URL to refresh. In this case page will be
refreshed after 10 seconds.
Redirecting User To Login Page after Session Timeouts.
Redirecting user
to login page after session timeout is similar to refreshing the page after
certain intervals method. Only thing which will differ is that calculating time
after which the page has to be redirected. Hence time can be calculated using
Session.timeout property which will give us session timeout value for that
session. Add some grace timings to that value and redirect the user to the login
page automatically.
Using
Window.setTimeout method
body.Attributes.Add("onLoad",
"window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout *
60 * 1000) + 10000 & ");")
Using
Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) &
"; URL=Login.aspx")
user to login page after session timeout + 10 seconds. This is how you can
redirect the user to login page after session timeout without user interaction.
Wednesday, May 5, 2010
Accessing Web site in IIS
Cannot publish the web site using Visual Studio (publish failed)
When you publish it will give you all the errors.
Songs for programming concepts
Jeena Yahan Marna Yahan,
Iske siva Jana kaahan.
Global variable
Musafir hoon yaaron,
na ghar hai na thikana
The debugger
Jab koi baat bigad jaye
Jab koi mushkil pad jaye
Tum dena saath mera hamnawaz
Grid with line numbers
<asp:templatecolumn
ID="templatecolumn1"
runat="server"
headertext="Row Number">
Datagrid Sort Example
void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e) {
Tuesday, May 4, 2010
To get month name from datetime picker in VB.NET
To get month name from datefield of a Table in SQL
Command for Redirecting all the file of a folder in a reverse order of Datewise.
To Convert variable of one datatype to other in SQL.
DECLARE @mybin1 binary(5), @mybin2 binary(5)
SET @mybin2 = 0xA5
-- No CONVERT or CAST function is necessary because this example concatenates two binary strings.
SELECT @mybin1 + @mybin2
-- A CONVERT or CAST function is necessary because this example concatenates two binary strings plus a space.
SELECT CONVERT(varchar(5), @mybin1) + ' ' + CONVERT(varchar(5), @mybin2)
New Line in Multiline TextBox in C#
Microsoft Agent in C#
AgentObjects.IAgentCtlCharacter Character;
string
sChar = @"C:\WINNT\msagent\chars\merlin.acs";
agtAgent.Characters.Load("merlin", sChar);
Character = agtAgent.Characters["merlin"];
Character.Show(null);
Character.Play("sad");
Character.Speak("Task
which are yet to completed are ", null);
Check selected value in CheckListBox in ASP.NET
for (int counter = 0; counter < ChecklistBox1.Items.Count; Counter++)
To get exact no. of days in particular month of a year.
dtpSalarySlip.Value.DaysInMonth(dtpSalarySlip.Value.Year,
dtpSalarySlip.Value.Month)
To get only date part from datetime field in sql stmt.
Enter data in subitem of particular item(i.e. rows) in Listview
listview1.Items[iRow-1].SubItems[2].Text =sCallDuration;
listview1.Items[iRow-1].SubItems[3].Text= sStatus;