Tuesday, April 28, 2009
Allow user to download files of different types
here is code for you if you want the users to download file from your web page (as image,.xsls,.xslt etc).
*************** Code from here *******************
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
Response.TransmitFile(Server.MapPath("foldername" + filename));
Response.End();
*************** Till here *************************
Content-Type -- You can set the content-type according to your file......
as if it is jpeg then content-type will be "image/jpeg"
below is list of some of content-type :
MS Word file --- application/msword
straight binary --- application/octet-stream
xml,xslt files ---- application/xslt+xml
RTF document --- application/rtf
PDF document --- application/pdf
ZIP document --- application/zip
you can view more about these at the below link :
http://www.asptutorial.info/sscript/ContentType.html
Thursday, April 23, 2009
Display images from database
Now a days developer like to save images to database.
Now the problem how to get image back from database.
For the same purpose we can use HttpHandler which can get the image from database.
and can be applied easily :
Here is code for that
you has to create a new generic handler.say its name is ImageViewer.ashx
here you put the following code in ProcessRequest() of the httphandler
context.Request.QueryString["ImageID"].ToString() // id of the row of database
Stream stream = null;
context.Response.ContentType = "image/jpeg/gif";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
int buffersize = 1024 * 16;
byte[] buffer = new byte[buffersize];
//Run your query here and get the binary stream from database assign it the stream variable as below
stream = stream from database;
int count = stream.Read(buffer, 0, buffersize);
while (count > 0)
{
context.Response.OutputStream.Write(buffer, 0, count);
count = stream.Read(buffer, 0, buffersize);
}
Now in the .aspx this what you need to do :
and you are done .
You can view the same here :
http://forums.asp.net/t/1394122.aspx?PageIndex=2
RegularExpressionValidator for image upload
you can
Using the RegularExpressionValidator you can validate it on client side .
Here is the code for this :
asp:regularexpressionvalidator runat="server" errormessage="Only picture files are allowed!" validationexpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.gif|.GIF|.jpg|.JPG|.jpeg|.JPEG)$" controltovalidate="fileUpload" display="None">
Wednesday, April 22, 2009
Fake player of the IPl part-2
there is one blog which is getting every body crazy these days.
here you can get lots of detail and funny things about the IPL-2.
Have a look at the link below and have fun :
http://fakeiplplayer.blogspot.com