1 Replies - 2226 Views - Last Post: 05 December 2010 - 04:08 PM Rate Topic: -----

#1 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

query string to handler page

Posted 05 December 2010 - 11:11 AM

does any one know how to do a query string from aspx page to handler page?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
using System.Net;


namespace Nap
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Response.Headers.Add("Content-Type", "image/jpeg");

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string PhotoPath = "";
            // Get the currently selected row. Because the SelectedIndexChanging event
            // occurs before the select operation in the GridView control, the
            // SelectedRow property cannot be used. Instead, use the Rows collection
            // and the NewSelectedIndex property of the e argument passed to this 
            // event handler.
            GridViewRow row = GridView1.Rows[GridView1.SelectedIndex];

            PhotoPath = row.Cells[5].Text;
            
            //TextBox1.Text = PhotoPath;
        }
    }
}
       


need to send photopath to my GetImage.ashx page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net;

namespace Nap
{
    /// <summary>
    /// Summary description for GetImage
    /// </summary>
    public class GetImage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            {

                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(context.Request.QueryString["PhotoPath"]));
                request.Method = WebRequestMethods.Ftp.DownloadFile;

                request.Credentials = new NetworkCredential("username", "password");

                try
                {
                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                    Stream stream = response.GetResponseStream();
                    byte[] bytes = new byte[2048];

                    int i = 0;
                    MemoryStream mStream = new MemoryStream();

                    do
                    {

                        i = stream.Read(bytes, 0, bytes.Length);

                        mStream.Write(bytes, 0, i);
                    } while (i != 0);

                    context.Response.Clear();
                    context.Response.ClearHeaders();
                    context.Response.ClearContent();
                    context.Response.ContentType = "image/jpeg";
                    context.Response.BinaryWrite(mStream.GetBuffer());

                }
                catch (WebException wex)
                {

                    //throw new Exception("Unable to locate or access your file.\\nPlease try a different file.");

                }
                catch (Exception ex)
                {
                    throw new Exception("An error occurred: " + ex);

                }

            }
        }

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

This post has been edited by Sparukus: 05 December 2010 - 11:12 AM


Is This A Good Question/Topic? 0
  • +

Replies To: query string to handler page

#2 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: query string to handler page

Posted 05 December 2010 - 04:08 PM

did i say this wrong?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1