Rami M. Nassar's Blog

Development, Beyound LifeStyle

July 2011 - Posts

Nice IE6 Upgrade Warning!

The ie6-upgrade-warning is a little script (7.9kb) (download it from here) that displays a warning message politely informing the user to upgrade the browser to a newer version (links to newest IE, Firefox, Opera, Safari, Chrome are provided). The webpage is still visible behind a transparent background, but access to it is prevented. The idea is to force users to upgrade from IE6 and avoid the website from a bad reputation that website is not rendering correctly in IE6 (note: if you are a sharepoint developer, then you’ll be happy with this script). The script is completely translatable in any language, very easy to set-up (one line of code in webpage and one parameter configuration).

IE6 Warning

Just insert the lines

<!--[if lte IE 6]-->
<script src="js/ie6/warning.js"></script>
<script>window.onload=function(){e("js/ie6/")}</script>
<!--[endif]-->
 

  right after the <body> declaration of the webpage and change the e("js/ie6/") to the folder where the script's icons images are located.  

Happy Programming Winking smile
Rami M. Nassar

Posted: Jul 15 2011, 01:43 AM by rami_nassar | with no comments
Filed under:
Preview image file before upload to webserver

You can use javascript to preview the selected image before uploading it to the server.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Main Page</title> 
 
    <script type="text/javascript">         
     
        function FileUpload1_onchange(oFileUpload1) 
        {       
          document.getElementById('Image1').src = oFileUpload1.value ; 
        }         
         
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:FileUpload ID="FileUpload1" runat="server" 
                 onchange="FileUpload1_onchange(this);"/> 
        <asp:Image ID="Image1" runat="server" /> 
    </form> 
</body> 
</html>


But due to security reasons, This doesn't work on some browsers. If this doesn't work for you, You'll have to save the image on some temporary location in server itself and preview it. You could try something like this :

 

.aspx

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Main Page</title> 
 
    <script type="text/javascript">         
     
        function FileUpload1_onchange(oFileUpload1) 
        {       
          document.getElementById('btnPreviewImage').click() ; 
        }         
         
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:FileUpload ID="FileUpload1" runat="server" 
            onchange="FileUpload1_onchange(this);" /> 
        <asp:Button ID="btnPreviewImage" runat="server" 
            Style="display: none;" OnClick="btnPreviewImage_Click" /> 
        <asp:Image ID="Image1" runat="server" /> 
    </form> 
</body> 
</html>

.aspx.cs

protected void btnPreviewImage_Click(object sender, EventArgs e) 
    { 
          if (FileUpload1.HasFile)   
         {   
             string path = Server.MapPath("TempImages");   
    
             FileInfo oFileInfo = new FileInfo(
                       FileUpload1.PostedFile.FileName);   
             string fileName = oFileInfo.Name;   
    
             string fullFileName = path + "\\" + fileName;   
             string imagePath = "TempImages/" + fileName;   
    
             if (!Directory.Exists(path))   
             {   
                 Directory.CreateDirectory(path);   
             }   
    
             FileUpload1.PostedFile.SaveAs(fullFileName);   
             Image1.ImageUrl = imagePath;   
         }   
    }

 

Happy Programming Smile
Rami M. Nassar

More Posts