code to download power point presentation file from one of my asp.net website
if (File.Exists(Server.MapPath(file)))
{
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/x-mspowerpoint";
Response.AddHeader("Content-Disposition", "attachment; filename=" + file);
Response.WriteFile(Server.MapPath(file));
Response.Flush();
}
Here Response.ContentType should be set correctly. I have used
"application/x-mspowerpoint" for powerpoint. You need to set
the correct ContentType. For example, for msword you should set
application/msword, for gif image you should set image/gif, for
pdf you should set application/pdf etc.
To get all columns names for all tables.
To get all columns names for all tables.
SELECT SO.NAME AS “Table Name”, SC.NAME AS “Column Name”, SM.TEXT AS “Default Value” FROM dbo.sysobjects SO INNER JOIN dbo.syscolumns SC ON SO.id = SC.id LEFT JOIN dbo.syscomments SM ON SC.cdefault = SM.id WHERE SO.xtype = ‘U’ ORDER BY SO.[name], SC.colid
for single table
SELECT SO.NAME AS “Table Name”, SC.NAME AS “Column Name”, SM.TEXT AS “Default Value” FROM dbo.sysobjects SO INNER JOIN dbo.syscolumns SC ON SO.id = SC.id LEFT JOIN dbo.syscomments SM ON SC.cdefault = SM.id WHERE SO.xtype = ‘U’ and SO.NAME=’TableName’ ORDER BY SO.[name], SC.colid
Query to find all PK, FK in a table.
SELECT f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keysAS f
INNER JOIN sys.foreign_key_columnsAS fc
ON f.OBJECT_ID= fc.constraint_object_id
SELECT*
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE =‘PRIMARY KEY’
SELECT
CONSTRAINT_NAME as Primary_key
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE =‘PRIMARY KEY’
AND
TABLE_NAME =’TableName‘‘
SELECT
CONSTRAINT_NAME as Primary_key
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE =‘PRIMARY KEY’
AND
TABLE_NAME =’TableName’
How to prevent a drag and drop text and Copy paste text in your textbox control
To prevent copy paste and drag in a textbox
<asp:TextBox ID="txtName" runat="server" onDrop="blur();return false;"
onpaste="return false" Width="150"> Because of blur() function the txtName lost its focus and we are not able to darg and drop the text.
Reverse of String.
Asp Page Life Cycle
Click here to download Page Life Cycle .Net
| Seq | Events | Controls Initialized | View state Available | Form data Available |
What Logic can be written here? |
| 1 | Init | No | No | No | Note: – You can access form data etc by using ASP.NET request objects but not by Server controls.Creating controls dynamically, in case you have controls to be created on runtime. Any setting initialization.Master pages and them settings.In this section we do not have access to viewstate , posted values and neither the controls are initialized. |
| 2 | Load view state | Not guaranteed | Yes | Not guaranteed | You can access view state and any synch logic where you want viewstate to be pushed to behind code variables can be done here. |
| 3 | PostBackdata | Not guaranteed | Yes | Yes | You can access form data. Any logic where you want the form data to be pushed to behind code variables can be done here. |
| 4 | Load | Yes | Yes | Yes | This is the place where you will put any logic you want to operate on the controls. Like flourishing a combox box from the database , sorting data on a grid etc. In this event we get access to all controls , viewstate and their posted values. |
| 5 | Validate | Yes | Yes | Yes | If your page has validators or you want execute validation for your page this is the right place to the same. |
| 6 | Event | Yes | Yes | Yes | If this is a post back by a button click or a dropdown change then the relative events will be fired. Any kind of logic which is related to that event can be executed here. |
| 7 | Pre-render | Yes | Yes | Yes | If you want to make final changes to the UI objects like changing tree structure or property values, before these controls are saved in to view state. |
| 8 | Save view state | Yes | Yes | Yes | Once all changes to server controls are done this event can be an opportunity to save control data in to view state. |
| 9 | Render | Yes | Yes | Yes | If you want to add some custom HTML to the output this is the place you can. |
| 10 | Unload | Yes | Yes | Yes | Any kind of clean up you would like to do here. |
Insert 1 to 100 Numbers into one column from one table
///////// Insert 1 to 100 Numbers into one column from one table ////////// create table with one column and run this query declare @x Int=1 While @x<=100 Begin insert into TableName(ColumnName)values(@x) Set @x+=1 end