Pages

Search This Blog

Saturday 5 July 2014

Code for sending SMS....

Hi friends, in this session I will show the code for sending messages using ASP.NET.

Messaging was so useful to us in many situations like sending confirmation code, sending passwords and etc...

Here I took two textboxes and two labels and one button for submit. 1 textbox is used to take phone number as input (ID=”tbphone”) and another textbox is for message (ID=”msg”) .

Here is the code....

using System.Net.Mail;

//Message code
  string sURL;
  StreamReader objReader;

 //Specify the API you used to send SMS in sURL

       sURL = "http://smsdaddy.in/webapi.php?username=xyz &password=abc&sender=id &to=" + tbphone.Text + "&message=Thank You for using our website " + msg.Text+ "   ";

        WebRequest wrGETURL = WebRequest.Create(sURL);
        Stream objStream;
        objStream = wrGETURL.GetResponse().GetResponseStream();
        objReader = new StreamReader(objStream);
        objReader.Close();
      
//Message code ends here 

 You can rate my class on right side top of my blog.......

                                                                       -Your's santoshklpkl

Wednesday 2 July 2014

How to store and retrieve image from Database in ASP.NET

Hi friends, today I will say you “how to store an image into database and how to retrieve image from database??”

Normally to upload an image into your application we use the tag called “Upload”.

Store.aspx:

<asp:FileUpload ID="FileUpload1" runat="server" />

Store.aspx.cs:

int img = FileUpload1.PostedFile.ContentLength;

byte[] msdata = new byte[img];

FileUpload1.PostedFile.InputStream.Read(msdata, 0, img);

SqlParameter p1 = new SqlParameter("@bill", msdata);

cmd.Parameters.Add(p1);

There is a data type known as “image” which is used to store an image into database tables. Normally, in user point of view the image is stored but if we see the data in the table it will store it in the form of binary code. This is because normally an image is consists of pixels that we can’t store in to our tables. So, database itself will store it in the form of binary code.

Here comes the real problem..... If the user wants to retrieve image from the database “He can’t .... Why??” because it was stored as binary code. To convert binary code into image we will use “Handlers”. First we must create a “Handler” and we will use that handler in our application where we need to display an image.

Handler.ashx:

<%@ WebHandler Language="C#" CodeBehind="Handler1.ashx.cs" Class="EEM.Handler1" %>

Handler1.ashx.cs:
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;

namespace EEM
{
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=Santosh-PC\\SQLEXPRESSGH;Initial Catalog=EEM;Integrated Security=True";

            // Create SQL Command
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Select Ticketcopies from Travel" +
                              " where Voucherid=@Voucherid";
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection = con;

            SqlParameter ImageID = new SqlParameter("@Voucherid", System.Data.SqlDbType.Int);
            ImageID.Value = context.Request.QueryString["Voucherid"];
            cmd.Parameters.Add(ImageID);
            con.Open();
            SqlDataReader dReader = cmd.ExecuteReader();
            dReader.Read();
            context.Response.BinaryWrite((byte[])dReader["bill"]);
            dReader.Close();
            con.Close();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

How to use handler in our application

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1"
                              
ForeColor="#333333" GridLines="None">
                                
<RowStyle BackColor="#EFF3FB" />
                              
 <Columns>
                                  
<asp:BoundField DataField="VoucherId" HeaderText="VoucherId"
 SortExpression="VoucherId" />
                                   
<asp:TemplateField HeaderText="Bill">

  <ItemTemplate>
   
   <asp:Image ID="Image1" runat="server" Height="150px" ImageUrl='<%#"Handler.ashx?VoucherId=" + Eval("voucherid")%>' Width="150px" />
                                      
   </ItemTemplate>

 </asp:TemplateField>
 
</Columns>

<FooterStyle BackColor="#0CB9BB" Font-Bold="True" ForeColor="White" />

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                               
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                               
<HeaderStyle BackColor="#0CB9BB" Font-Bold="True" ForeColor="White" />
                               
<EditRowStyle BackColor="#2461BF" />
                               
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:EEMConnectionString %>"
     SelectCommand="SELECT * FROM [Medical]"></asp:SqlDataSource>

                        

Tuesday 1 July 2014

How to add new pages and images into project.

Hi friends, “In this is session I will show you how to add new page and pictures into your project”.

A project can't be done with in one page. It must navigate from one page to another page and it will do many activities. So we need to create many pages in our website. Some times we need to add already

Some times we need to use pictures in our website. So it looks more better and nice. Some time awesome also.

Steps to add a page/picture..

Step 1: 

Create a project

Step 2:

Go to view--> Solution Explorer

Step 3:

Right click on project name "Sample" --> Add new item/ Existing item  

Step 4:

Create/Select the page/image 

Step 5:

Ok



That's it. Now a new page/image was added into your project.

You can rate my class on right side top of my blog ....
                          
                                                                      -Your's Santoshklpkl
Animated Social Gadget - Blogger And Wordpress Tips Twitter Bird Gadget