Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this ASPX page..

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .FileSelect
        {
            background-image: url('../Images/Camera.png');
            width: 120px;
            height: 90px;
        }
    </style>
    <script type="text/javascript">
        function SelectFile() {
            document.getElementById('<%= imageUpload.ClientID %>').click();
        }
        function SubmitForm() {
            __doPostBack('btnSubmit', '');
        }
        function __doPostBack(eventtarget, eventargument) {
            document.form1.__EVENTTARGET.value = eventtarget;
            document.form1.__EVENTARGUMENT.value = eventargument;
            document.form1.submit();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">    
        <input type="hidden" id="__EVENTTARGET" value="" />
        <input type="hidden" id="__EVENTARGUMENT" value="" />
        <input type="button" runat="server" id="btnFileSelect" value="" class="FileSelect" onclick="SelectFile();"/> 
        <asp:FileUpload ID="imageUpload" runat="server" style="display:none;" onchange="SubmitForm()" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" style="display:none;" />    
    </form>
</body>
</html>


and in my code behind page like this..

C#
protected void Page_Load(object sender, EventArgs e)
       {
       }
       protected void btnSubmit_Click(object sender, EventArgs e)
       {

       }


when __doPostBack is Called at that time the line

JavaScript
document.form1.submit();
will give me this error

"htmlfile: Access is denied"

how to resolve this...
Posted
Updated 13-Oct-11 10:50am
v3

1 solution

You cannot call the click() method from javascript of a FileUpload control. It also isn't possible to set or clear the value using javascript. It is considered a security violation. You could however read the value to check the file extension for example.

Some extra info:
http://codecorner.galanter.net/2009/03/10/fileupload-and-htmlfile-access-is-denied-error/[^]

http://jonesie.net.nz/htmlFileAccessDeniedADefenceForMurder.aspx[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900