Tuesday, 17 December 2013

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack


Solved : Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Reason:
     The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.
Solution: 
For Response.Redirect
Response.Redirect ("nextpageURL.aspx", false);
For Server.Transfer
Use Server.Execute instead of Server.Transfer

Separate characters in a string using SPLIT and ARRAY

The SPLIT will separate the characters using a unique character or symbol like + , . @_ - etc. and store values in the ARRAY.

Example :

protected void buttonname_Click(object sender, EventArgs e)
{
string a = It-is-a-demo;

string[] b = a.split('-');  //It will split the characters after each of this special character underscore -

string split1 = b[0];  //It will be stored using the array
string split2 = b[1];  // is will be stored
string split3 = b[2];  // a will be stored
string split4 = b[3];  // demo will be stored

lbllaststring.Text = split4;  //demo will be displayed in the label
}

Saturday, 27 July 2013

How to Create the SQL Stored Procedure


Open the SQL server 2005 or 2008 and then create a database and the tables and add the fields as your requirement.Here in this example I use two fields.

ID  int
Name  Varchar(50)

Now Click the New query and the Type following Stored Procedure :

USE [DBNAME]

GO

CREATE procedure Sp_Tblname
@ID int=0,
@Name varchar(50)=null,
@Mode varchar(100)=null
as
begin

if @Mode='Insert'
Insert into Tblname(Name) values (@Name)
end

if @Mode='Update'
begin
update Tblname set Name=@Name where ID=@ID
end

if @Mode='Delete'
begin
Delete from Tblname where ID=@ID
end

if @Mode='Selectall'
begin
Select * from Tblname
end

end

This is the simple stored procedure created using sql.After completing it u can Execute it.
After this u can call these parameters and stored procedure as shown in this link http://sathyadotnet.blogspot.in/search/label/3-Tier%20Architecture.

Thursday, 25 July 2013

How To Back Up Complete BLOG and Template



Here the Entire BLOG can be back up through Google takeout(https://www.google.com/takeout/#custom) and also directly from your BLOG.First I tell you how to back up using Google takeout and then from the blog directly.

Back up Blog using Google TakeOut:

1, Login to https://www.google.com/takeout/#custom using your respective blog account.

2, After that Click Choose services and then in the Select service choose Blooger

3, Select the “Create Archive” button.
4, Once the progress bar reaches 100%,Click Download(It automatically compress the file and start downloading)

5,Thats it!!! YOUR BLOG BACK UP GETS OVER.

Back up Blog directly from your Blog:
1, Open your blog and then Sign In
2, Then go to Settings from Design or Dashboard.
3, Click the Other options from Settings tab.

4, Look at the Blog Tools: Import Blog - Export Blog - Delete Blog.
5, Hit on the Export Blog.

6, Now click Download Blog.

7, Save the .xml file in your hard disk.

Then If you wanna restore your blog from that previously saved copy then follow the above steps again. Just in the step 5 you have to Choose Import Blog. Then choose and upload the .xml file that you've saved in your hard disk...

Back up your Blog Template:
1, Open your blog and then Sign In
2, Then go to Template from Design or Dashboard.
3, Now Click Backup/Restore at the top right as shown
4, Then click the Download the template and save it in XML format.


If you want to Upload that saved file follow the same but at Step4 click the choose file and then click Upload.


Friday, 19 July 2013

ADD SMOOTH BACK TO TOP BUTTON FOR BLOGGER

If you have lot of contents in your blog pages, and if you want to make your blog to be easy to navigate for your readers, a back to top button will make it easy and perfect....

Step 1: Log on your blogger account and Go to, Dashboard > Template > Edit html.

Step 2: Find the following tag by using "Ctrl + F".

]]></b:skin> 


Step 3: Copy and Paste below code before the above tag.

#backtotop {
padding:5px;
position:fixed;
bottom: 5px;
right: 5px;
cursor:pointer;
}


Step 4: Find the </body> tag by using "Ctrl + F" and copy and paste below code before the </body> tag.

<a href="#" id="backtotop"><img src="Image Url" alt="back to top" /></a>

Step 5: Now select your free back to top button in the below list and copy and paste it’s Image URL in to the place of "Image Url" of above code.



 

1. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgd9SBqUcL5aZc2asOck9bGTQUljlDnAThyphenhyphen5nuBvnEdK27kjZWD5V0K14SQovGVBazmqsQJlO1aLCLYNAKTHafDphcIUmkhhRETAqV3dao-DHP4kVv8MlTL6gdyqs_1rUc4B-anA4Jm5K6/s1600/new+back+to+top+button.png

back_to_top image 
2. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUGGqzjbdtW9ZNaMhKHeomD4OPbIu-4aY83RqIyceGCiEyVvgSCRmq3TzVpaw8o89sKnLibU8vjm9wN1q14CFM_55ifuLfqosMpPeCh5yWelJa9gzCa_41UIAnh7PeYP-gV-jBmfhTD06g/s1600/back+to+top+button.png
back to top gadget
3. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBj6mb4yAXdzo9_iqYWxTQmdHnL9XEr9AkukO4w5DmA691Qyy6fl9pNrBgE0TZfTOB2kgV1p0qat1MfKSqjz9J8r81Qyxl3FBys4jAdxHLn0fcFzDofcKO5N-7C3JSLO55iKoSDJhnXMGw/s1600/Back_to_top_image.png

back to top classic button
4. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixFVpHm2sY0E9rB-eCKT99dJ9fLY77t_FtSzLYaov0zT_ayToftbSxg2PoCwSc1slO6RJHao_amGGdmyzwZsLz0nuRC_HDTU1Pq2t2grr5Y96GJTDcp9KP4MoJwuw6rC0_udu7IgAGs7Hj/s1600/back_to_top.png


back to top

5. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii4hq1S7UVfZ1TCmqEczG9N7-vEF7Bliol20fHHPVz_iUN3TTzibiV_iMXhtfC3i5bDs-oyHITH29q361cLZ6zN-P-FG-9CJ7XIHucnMlkgGNmK8rXqoSqsOeNRDtrOZFWxDYTM4sIF-aG/s1600/back+to+top+icon.png



6. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_JijpcKQdoUgfB2HYoLLLgdLWbkKU8w7Dm6tcgFfV88UeJpcr2SZ0yMGZHH8eNfaZdj20B_l7G5zcu2zrAwq4PdiQ-GNcYBafIM7oK9VxWO_HFqa1hzhNiU8bye4_7PfYN8To7moat3fC/s1600/back_to_top_button.png

 
7. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXoMB4VH-h9x9HQQnVuNUeT36LGs1A39GIAKSgpLlF5Ijw_EB1oCvp_tqfvCbqAdIJkFWz7i9QdbWQbHGfv7R0Lti_R0MokwCcmRypqgyJh-uWUHKk8PQOBXfIwd4tARv7M4rQo97Xiyaf/s1600/back+to+top.png

back to top button
8. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioOyBLD_XntPDNryYCA_z3WFKl4zjtKCP_aUtHoXk5jOn46Ufg1MNMS1KnLC6af4toOfyo9ctmChC28hoO2tvLF6yBinnLHxN8Ae4jsfzh3XYKH3t7fur9xv5MCpN6NMQ00dEf7Pek2cqJ/s1600/back+to+top.png



Step 6: Find the <head> tag by using "Ctrl + F" and copy and paste below code after the <head> tag and save template..

<!-- start back to top -->
&lt;script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'
type='text/javascript'&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot;&gt;
$(window).ready(function(){
$('#backtotop').click(function(e){
e.preventDefault();
$('html, body').animate({scrollTop:0}, 'slow');
});
});
&lt;/script&gt;
<!-- end back to top -->

Wednesday, 17 July 2013

CSS properties


The following are the CSS properties arranged in the alphabetical order

A
align-content
align-items
align-self
animation
appearance
B
backface-visibility
background
border
border-collapse
border-image
border-radius
bottom
box-shadow
box-sizing
C
clear
clip
color
column-count
content
counter-increment
counter-reset
cursor
D
direction
display
F
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
float
font
font-family
font-size
font-stretch
font-style
font-variant
font-weight
G
grid
H
hanging-punctuation
height
hyphens
J
justify-content
L
left
letter-spacing
line-height
list-style
M
margin
max-height
max-width
min-height
min-width
O
opacity
order
orphans
outline
overflow
P
padding
page-break
perspective
perspective-origin
pointer-events
position
Q
quotes
R
resize
right
S
scrollbar
T
tab-size
text-align
text-decoration
text-indent
text-overflow
text-shadow
text-stroke
top
transform
transform-origin
transform-style
transition
U
unicode-bidi
user-select
V
vertical-align
visibility
W
white-space
widows
width
word-break
word-spacing
Z
z-index
zoom

Box/DIV Shadows using CSS

Apply the following CSS for the shadow effect in the DIV's

.shadowdiv
{

-webkit-box-shadow: 0 0 5px 2px #000;
-moz-box-shadow: 0 0 5px 2px #000;
box-shadow: 0 0 5px 2px #000;

}
1st 0 is the horizontal offset of the shadow,this 0 will give shadow on both the left and right side of the div,Positive value like 2px will give shadow on right side and Negative value like -2px will give shadow on left side.

2nd 0 is the vertival offset of the shadow,this 0 will give shadow on both the top and bottom of the div,Positive value like 2px will give shadow on below and Negative value like -2px will give shadow on top.
  
5px is for the blur of the shadow.Higher the value,higher the Blurness.0 will give sharp shadow.  

2px is for spread radius or thickness of the shadow.positive increase the size and negative decrease size.

#000 is the color of the shadow.We can change to any color as required.

<html>
<head>
<style type="text/css">

.shadowdiv
{

width:200px;
height:200px; 
-webkit-box-shadow: 0 0 5px 2px #000;
-moz-box-shadow: 0 0 5px 2px #000;
box-shadow: 0 0 5px 2px #000;

}

</style>
</head>
<body>

<div class="shadowdiv">
Hi,This is an example div for the box shadow
<div> 

</body>
</html>

Tuesday, 16 July 2013

Extract Characters using Substring in SQL

Substring in SQL will Extract the characters from an starting point of the strings in the column name of the database.The syntax for it is

SUBSTRING(string or column name, startIndex, length)
string denotes the columnname or the string value
start index denotes the starting point from where extraction begins
length denotes the how many characters to be extracted.

Example Select query using substring:
SELECT SUBSTRING(Names,2,3) as 'substring' FROM TABLENAME
This query will return Names starting from 3 and return 3 characters from the strings in that columname. 

Monday, 15 July 2013

How to use Substring in Asp.net C#


The Substring method is used to extract the characters from any part of the string.The syntax is

Substring( start_position, num_of_chars_to_grab )

Example:

Substring(0,2)
0 is the starting index of the string
2 is the length or number of characters to be grab or extract.

Example to extract characters form a string using Textbox,Label and Button.

protected void Button1_Click(object sender, EventArgs e)

{

string a = TextBox1.Text.ToString();

string b = a.Substring(2, 2); //Extract 2 characters start from the 2 index position

Label1.Text = b.ToString();

}

Friday, 5 July 2013

Delete Confirmation box in the asp.net Grid view

Create a page with the gridview in the .aspx page as below

<html>
<head runat="server">

<script type="text/javascript">

function ConfirmationBox(Name) {

var result = confirm('Do you want to delete '+ Name +' Details' );

if (result) {

return true;
}

else {

return false;
}
}
</script>

</head>

<body>

<form id="form1" runat="server">
<div>

<asp:gridview autogeneratecolumns="false" datakeynames="Uid" id="deletegrid" onrowdatabound="deletegrid_RowDataBound" runat="server">

<columns>

<asp:boundfield datafield="Name" headertext="Name"/>
<asp:boundfield datafield="Mobile" headertext="Mobile"/>
<asp:boundfield datafield="Full Name" headertext="Fullname"/>

<asp:templatefield headertext="Delete"/>

<itemtemplate>

<asp:linkbutton id="deltlnkbtn" onclick="deltlnkbtn_Click" runat="server">
Delete User</asp:linkbutton>

</itemtemplate>

</asp:templatefield>

</columns>

</asp:gridview>

</div>
</form>
</body>
</html>
Now enter the following code in the .aspx.cs code behind as
SqlConnection con = new SqlConnection("Data Source=localhostname;Integrated Security=true;Initial Catalog=DBname");

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

BindUser();

}
}

protected void BindUser()
{
//connection open
con.Open();

//sql command to execute query from database
SqlCommand cmd = new SqlCommand("Select * from tablename",con);

cmd.ExecuteNonQuery();

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

//Bind data to gridview
deletegrid.DataSource = ds;
deletegrid.DataBind();

con.Close();
}
protected void deletegrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//get the name from a row
string Name =Convert.ToString(DataBinder.Eval(e.Row.DataItem,"Name"));

//identifying the control in gridview
LinkButton lnkbtns = (LinkButton)e.Row.FindControl("deltlnkbtn");

//raising javascript confirmationbox while clicking the link button
lnkbtns.Attributes.Add("onclick", "javascript:return ConfirmationBox('" + Name + "')");
}
}

protected void deltlnkbtn_Click(object sender, EventArgs e)
{

LinkButton lnkbtn= sender as LinkButton;

//get the particular row linkbutton
GridViewRow delgvrow = lnkbtn.NamingContainer as GridViewRow;

//get the userid of particular row
int userid = Convert.ToInt32(deletegrid.DataKeys[delgvrow.RowIndex].Value.ToString());

string Name = gvrow.Cells[0].Text;

con.Open();
SqlCommand cmd = new SqlCommand("delete from UserDetails where Uid="+Uid,con);

int temp=cmd.ExecuteNonQuery();

con.Close();

if (temp == 1)
{

BindUser();

//Displaying alert message after successfully deletion of user
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + Name + " deleted successfully')", true);
}
}

Monday, 1 July 2013

Flying Image from one cart to another

<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <!-- Script for flying image --> <script type="text/javascript"> $(document).ready(function(){ $(".productPriceWrapRight a img").click(function() { var productIDValSplitter = (this.id).split("_"); var productIDVal = productIDValSplitter[1]; var productX = $("#productImageWrapID_" + productIDVal).offset().left; var productY = $("#productImageWrapID_" + productIDVal).offset().top; var basketX = $("#basketTitleWrap").offset().left; var basketY = $("#basketTitleWrap").offset().top; var gotoX = basketX - productX; var gotoY = basketY - productY; var newImageWidth = $("#productImageWrapID_" + productIDVal).width() / 3; var newImageHeight = $("#productImageWrapID_" + productIDVal).height() / 3; $("#productImageWrapID_" + productIDVal + " img") .clone() .prependTo("#productImageWrapID_" + productIDVal) .css({'position' : 'absolute','border-width':'5px','border-color':'red','border-style':'dotted'} .animate({opacity: 0.5}, 100 ) .animate({opacity: 0.2, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {   $(this).remove(); }); }); });
</script> </head> <body> <form id="form1" runat="server"> <div> <!-- Datalist can also be used --> <!-- add images in the gridview dynamicaly from the database --> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > <Columns> <asp:TemplateField  HeaderText="Model"><ItemTemplate> <div class="productImageWrap" id="productImageWrapID_<%# Eval("ID") %>"> <img src = '<%# "Handler.ashx?ID= " + Eval ("ID") %> ' id = "img" /> </div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField  HeaderText="Model"> <ItemTemplate> <div class="productPriceWrapRight"> <!-- a href tag can also be used --> <asp:LinkButton ID="a" CommandName="select" runat="server"> <img src="images/add-to-basket2.gif" alt="Add To Basket" width="111" height="32"id="featuredProduct_<%# Eval("ID") %>" /> </asp:LinkButton> </div> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </div> <div> <div id="basketTitleWrap"> Your Basket </div> </div> </form> </body> </html>

Wednesday, 19 June 2013

JAVASCRIPT VALIDATION FOR PASSWORD COMPARISION

<html>
<script type="text/javascript">
function checkPass() {

var pass1 = document.getElementById("<%=txtpassword.ClientID %>");
var pass2 = document.getElementById("<%=txtconformpass.ClientID %>");

var message = document.getElementById('confirmMessage');

var goodColor = "#66cc66";
var badColor = "#ff6666";

if (pass1.value == pass2.value)
{
message.style.color = goodColor;
message.innerHTML = "Passwords Match!"
}
else
{
message.style.color = badColor;
message.innerHTML = "Passwords not match!"
}
} 
</script>
<body>
<form id="form1" runat="server">

<label>Password</label><asp:TextBox ID="txtpassword" runat="server"
Width="160px" TextMode="Password"></asp:TextBox>
<br /><br />
<label>Conform Password</label><asp:TextBox ID="txtconformpass" runat="server"onKeyup="checkPass()" Width="160px" TextMode="Password"></asp:TextBox>
<span id="confirmMessage" class="confirmMessage"></span>  </form> </body>
</html>

Wednesday, 24 April 2013

How to store date and time separately using datetime picker in C#


Click Add New Item --> Select Windows Form --> Click Toolbox --> Select 2 datetime pickers as
dateTimePicker1 and dateTimePicker2.

Right Click on dateTimePicker1 --> Select properties --> Select Format --> Change it to Short .
Similarly Right Click on dateTimePicker2 --> Select properties --> Select Format --> Change it to Time .

Now Add an Button(button1) and name it as Insert.

Now Double click on the button, the coding .cs page will be opened. In that for the button click event write the following code.

private void button1_Click_1(object sender, EventArgs e)
{

datevalue = Convert.ToString(dateTimePicker1.Value);

DateTime tdate = DateTime.Now;

vdate = Convert.ToDateTime(datevalue);

datevalue= vdate.ToString("yyyy-MM-dd");

string timevalue = Convert.ToString(dateTimePicker2.Value);
DateTime vtime = DateTime.Now;

vtime= Convert.ToDateTime(timevalue);

timevalue = string.Format("{0}:{1} {2}", tt.Hour, tt.Minute, tt.Hour > 12 ? "PM" : "AM");

SqlConnection con = new SqlConnection ("Data Source=.\\SQLEXPRESS; Initial Catalog=sampledb;Integrated Security=True");

con.Open();

SqlCommand cmd = new SqlCommand("INSERT INTO TABLENAME (datefield,timefield)
VALUE ('" +datevalue+"','" +timevalue+"')", con); //Create database with fields datefield,timefield

cmd.ExecuteNonQuery();

con.Close();
}

Friday, 19 April 2013

3 - Tier architecture Asp.net C#

The 3- Tier architecture consists of 3 layers.They are
Application Layer or Presentation Layer
Buisness Logic Layer(BLL) or Buisness Access Layer(BAL)
Data Access Layer(DAL)

Application Layer or Presentation Layer

This layer is for contains the UI part.Through this layer only we get the input. FOR EXAMPLE:  In the aspx page textbox , button,etc... are used for getting the input and to display or present the output.

Here i will show an example to insert the username and password using 2 text boxes and a button.Write the following in the "userinsert.aspx" page.

<asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
<asp:TextBox ID="txtpassword" runat="server"></asp:TextBox>
<asp:Button ID="btninsert" runat="server">Insert</asp:Button>

Buisness Logic Layer(BLL) or Buisness Access Layer(BAL) 

This layer acts as a interface between Application layer and Data Access Layer.Here we use this layer to assign the parameters i.e, get and set and other calculations related with the data like insert data, retrieve data and validating the data.

Right click on your project web application---> select add new item ----> select class file in wizard --->give name as userBLL.CS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Data;

public class userBLL

{

    userDAL DAL;
public userBLL()
{
        DAL = new userDAL(this);
}

    private string _UserName;
    private string _Password;
    

    private string _Mode;
    private string _Procedure;
  


    public string UserName    {
        get
        {
            return _UserName;
        }
        set
        {
            _UserName = value;
        }
    }

    public string Password

    {
        get
        {
            return _Password;
        }
        set
        {
           _Password = value;
        }
    }

   public string Mode

    {

        get
        {
            return _Mode;
        }
        set
        {
           _Mode = value;
        }
    }

    public string Procedure
    {
        get
        {
            return _Procedure;
        }
        set
        {
            _Procedure = value;
        }
    
    }


   public void Insert(string Connect)
    {
        DAL.Insert(Connect);
    }
  }

Data Access Layer(DAL)
This Layer contains methods or procedures to connect with database and to perform insert,update,delete,get data from database based on our input data.
Right click on your project web application---> select add new item ----> select class file in wizard --->give name as userDAL.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

public class userDAL
{

    userBAL BAL;
    SqlConnection Con;
    SqlCommand cmd;

     public userDAL(userBAL BAL1)
    {
     BAL=BAL1;
    }
      public void Connection(string Conn)
    {
        Con = new SqlConnection(Conn);
        if (Con.State == ConnectionState.Closed)
        {
            Con.Open();
        }
    }
    public void Insert(string Connect)
    {
        Connection(Connect);
        cmd = new SqlCommand(BAL.Procedure, Con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = BAL.UserName;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = BAL.Password;     
        cmd.Parameters.Add("@Mode", SqlDbType.VarChar).Value = BAL.Mode;
        cmd.ExecuteNonQuery();
        Con.Close();
    }
}

Now BLL and DAL are ready.Now once again return to the application layer and write the following in the button click event of the "userinsert.aspx.cs" page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
string Conne = ConfigurationManager.ConnectionStrings["Connects"].ConnectionString.ToString();
    userBAL BAL = new userBAL();

  protected void Button1_Click(object sender, EventArgs e)
    {
        BAL.UserName =txtusername.Text;
        BAL.Password = txtpassword;
        BAL.Mode = "Insert"; //Stored procedure for insert
        BAL.Procedure = "SP_Tbl_userinsesrt"; //Stored procedure name 

        BAL.Insert(Conne);
    }

Thats it..3 Layers are completed.Now its ready to run....


Friday, 15 March 2013

UPLOADING AND DOWNLOADING THE PDF FILES FROM THE DATABASE


CREATE TABLE [dbo].[books]
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[Pdlfiles] [varbinary](max) NULL,
[File name] [varchar](max) NULL
)

CREATE A PAGE FOR UPLOADING PDF AS addpdf.aspx AND ADD THE FOLLOWING
         <label>PDF FILE</label>
         <asp:TextBox ID="txtauthor" runat="server"></asp:TextBox>
         <br />
         <label>FILE NAME</label>
         <asp:FileUpload ID="fileupldsample" runat="server" />
         <br />
         <asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />

   
IN THE  addpdf.aspx.cs PAGE  ADD THE FOLLOWING
// This namespace should be there
using System.IO;
 protected void btnupload_Click(object sender, EventArgs e)
 {
if(fileupldsample.HasFile)
{
Stream fs = default(Stream);
fs = fileupldsample.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] pdfbytes = br.ReadBytes(fileupldsample.PostedFile.ContentLength);
SqlCommand cmd = new SqlCommand("insert into tablename",);
}
 }
back to top