Posts

Showing posts from February, 2012

Open Custom Help File on F1 press

Image
Hello readers, This is new topic for which i have written a code. When we press F1 key then its opens the help for that document and same when we a running any web application or internet and if we press F1 key then it opens the browser help. So here is the scenario, I want to open my own created help file on pressing F1 key. The code is not much complicated. Just we have to trap the F1 key code and cancel its default function and perform the action to open my own created help file that is a word document file. We have to use JavaScript to trap F1 event. After that we retrieve the page URL and its name and open a new popup window by passing file name in query string. To make it more simple to identify which file has to be opened for the current page, I named the help files as the page name. for example if page name is abc.aspx then its help file name is abc.doc. ASPX Page Code   :   <% @ Page Language ="C#" AutoEventWireup ="true" CodeFile ="Default

Check Content Type of a file before uploading it to server

Hello readers. Below is the small but an important code to check file contents before uploading to server. There may be a chance that the user want to play with the file upload code. Suppose user want to upload a file, but instead of uploading an image file, he changes the extension of a text file from .txt to .jpg and click on upload,,,,, File uploaded. Because code is checking for extension of uploading file not for the content so he can use the trick to upload an invalid file. To prevent this trick read the code. Code is self explanatory and simple. Just by checking the content type of file. Remember that first check the length of file. If it is greater than than 0 then proceed next, because if you rename a text file .txt to .jpg without writing and text in it, its content type becomes the image content type an user is able to upload a invalid image file of size 0 bytes. After this you can use the rest of code to check maximum file size. ASPX Page Cdoe <% @ Page Language =&q