Thursday, 17 January 2013 13:55

how to read from a file according to querystring using Stream

Written by 
Rate this item
(0 votes)

if you want to read get/read data from a file according to
querystring using StreamReader then following codes will
help you.It is very useful in some case.here i get data from
a ashx file according to query string i pass to the file -

use these codes in your code behind file -

WebClient client = new WebClient();
using (Stream stream = client.OpenRead("http://localhost/license/main.ashx?order=1&email=This email address is being protected from spambots. You need JavaScript enabled to view it.))
{
using (StreamReader reader = new StreamReader(stream, Encoding.Default))
{
string input = reader.ReadToEnd();
lblResult.Text = input;//lblResult is a textbox
}
}

the codes in ashx file are -

namespace MITSOL
{
public class main : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpResponse r = context.Response;
r.ContentType ="text/plain" ;

string file = context.Request.QueryString["order"];
if (order == "1")
{
r.Write("ok");
//you can get any data from here to pass
}
else
{
r.Write("wrong");
}
}
public bool IsReusable {get{return false;}}
}
}

Read 3104 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.