We need to set the appropriate MIME content-type and additionally, want to "Force" a download dialog with a custom filename in response to the click event.
void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack){
FileStream MyFileStream = new FileStream(@"d:\inetpub\wwwroot\small.pdf",
FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.ContentType="application/pdf";
Response.AddHeader( "content-disposition","attachment; filename=MyPDF.PDF");
Response.BinaryWrite(Buffer);
}
}
Imports System
Imports System.Web
Imports System.IO
Namespace LovesPYT
Public Class FileHandling
Shared Public Sub DownloadFile(FilePath as String, Optional
ContentType as String = "")
If File.Exists(FilePath) Then
Dim myFileInfo as FileInfo
Dim StartPos as Long = 0, FileSize as Long, EndPos as Long
myFileInfo = New FileInfo(FilePath)
FileSize = myFileInfo.Length
EndPos = FileSize
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Dim Range as String =
HttpContext.Current.Request.Headers("Range")
If Not ((Range Is Nothing) or (Range = "")) Then
Dim StartEnd as Array =
Range.SubString(Range.LastIndexOf("=")+1).Split("-")
If Not StartEnd(0)="" Then
StartPos = CType(StartEnd(0), Long)
End If
If StartEnd.GetUpperBound(0) >= 1 and Not StartEnd(1)="" Then
EndPos = CType(StartEnd(1), Long)
Else
EndPos = FileSize-StartPos
End If
If EndPos > FileSize then
EndPos = FileSize - StartPos
End If
HttpContext.Current.Response.StatusCode=206
HttpContext.Current.Response.StatusDescription="Partial
Content"
HttpContext.Current.Response.AppendHeader("Content-Range",
"bytes " & StartPos &"-"& EndPos & "/" & FileSize)
End If
If Not (ContentType="") and (StartPos = 0) Then
HttpContext.Current.Response.ContentType = ContentType
End If
HttpContext.Current.Response.AppendHeader("Content-disposition",
"attachment; filename=" & myFileInfo.Name)
HttpContext.Current.Response.WriteFile(FilePath, StartPos,
EndPos)
HttpContext.Current.Response.End()
End If
End Sub
End Class
End Namespace
Session redirect Code
Response.AppendHeader("Refresh", Convert.ToString(Session.Timeout * 60) & "; URL=PageExpired.aspx")
Source from http://www.eggheadcafe.com/articles/20011006.asp
Sunday, August 19, 2007
Wednesday, August 15, 2007
Independence day - Now 60
Aug. 15, 1947: Mountbatten swears Nehru in as Prime Minister of IndiaTRAIN TO PAKISTAN; India 1947. Trains packed with refugees - Hindus and Sikhs headed for India, and Muslims headed for Pakistan - were convenient targets for gangs of killers on both sides of the border. Inadequately protected 'Refugee Specials' were typically stopped, and the occupants butchered, several times in the course of the journey.
The dead - Punjab, 1947
1971: Indira Gandhi reviews the troops, in the context of militaryand diplomatic preparations for the Bangladesh War. Ghandhiji Addressing people Nehru and Gandhi at AICC meeting, July 1946 Mountbatten arrives at Delhi airport; received by Nehru and Liaquat Ali. March 25, 19471948: The news of Gandhi's assassination hits the streets. A stunned crowd gathers in Calcutta1948: Crowds in New Delhi wait for a glimpse of Gandhi's funeral procession. A Library being divided at the time of partition. Heart trembles to see this sight and it is tough to imagine the state of the nation at the moment when people needed to hold hands. Jai Hind
Bala
Tuesday, August 14, 2007
Correlated subqueries
In the sub query, SQL evaluates the subquery once, substitutes the result of the subquery in the search condition, and evaluates the outer-level SELECT based on the value of the search condition. You can also write a subquery that SQL may need to re-evaluate as it examines each new row (WHERE clause) or group of rows (HAVING clause) in the outer-level SELECT. This is called a correlated subquery.
We use the correlated subquery in the following clause
(
SELECT Boss.emp_name FROM dbo.Tbl_Employee Boss
WHERE Boss.id = Emp.boss_id
) [Boss Name]
FROM
dbo.Tbl_Employee Emp
We use the correlated subquery in the following clause
- Correlated subquery in select-list
- Correlated subquery in a WHERE Clause
- Correlated subquery in a HAVING Clause
- Correlated subqueries in an UPDATE statement
- Correlated subqueries in a DELETE statement
I tried to test the sub query in Select-List and the following scripts will assist you to try the query.
DDL
CREATE TABLE Tbl_Employee
(
id NUMERIC,
emp_name VARCHAR(50),
boss_id NUMERIC
)
DML
INSERT INTO dbo.Tbl_Employee values
(1,'Sandya',1)
INSERT INTO dbo.Tbl_Employee values
(2,'Nidya',1)
INSERT INTO dbo.Tbl_Employee values
(3,'Ramya',1)
INSERT INTO dbo.Tbl_Employee values
(4,'Priya',2)
INSERT INTO dbo.Tbl_Employee values
(5,'Balakrishnan',1)
Sample Query
SELECT Emp.emp_name [Employee Name],(
SELECT Boss.emp_name FROM dbo.Tbl_Employee Boss
WHERE Boss.id = Emp.boss_id
) [Boss Name]
FROM
dbo.Tbl_Employee Emp
Result
Saturday, August 11, 2007
Friday, August 10, 2007
Wab link and Log Analizing tools
SSW Link auditor - To check the broken links
Xenu's link sleuth - To check the broken links
123 Log analyzer - IIS Log analyser
Subscribe to:
Posts (Atom)