TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shalini Shines
NA
1
623
How to Connect two Generic Handler c# asp.net
Apr 21 2015 1:58 AM
Generic_Handler.ashx
<%@ WebHandler Language="C#" Class="Generic_Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
public class Generic_Handler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
string id = context.Request.QueryString["ID"];
byte[] bytes;
string FileType;
string strConnString = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Video, FileType from TBL_YouTube where ID=@ID";
cmd.Parameters.AddWithValue("@ID", id);
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
bytes = (byte[])sdr["Video"];
FileType = sdr["FileType"].ToString();
con.Close();
}
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.AppendHeader("Content-Disposition", "attachment; ID=" + id);
context.Response.ContentType = FileType;
context.Response.BinaryWrite(bytes);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
Search.ashx
<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Text;
public class Search : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string searchText = context.Request.QueryString["q"];
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Videos;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select FileName from TBL_YouTube where FileName Like @Search + '%'", con);
cmd.Parameters.AddWithValue("@Search", searchText);
StringBuilder sb = new StringBuilder();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
sb.Append(string.Format("{0},{1}", dr["FileName"], Environment.NewLine));
}
}
con.Close();
context.Response.Write(sb.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
Reply
Answers (
0
)
How to work with api bonanza
dynamically continue or running date time from database