You must Sign In to post a response.
  • Category: JavaScript

    Access denied Error while uploading file using javascript

    hi
    i have linkbutton,a file upload and a button on my page.file upload and button are in a div that is hidden so that the user will only see linkbutton.
    now on click of linkbutton i am opening file upload dialouge. and when user will select file to upload i am clicking button through javascript that will upload the selected file.but as soon as user selects the file to upload the javascript runtime error is thrown as 0x80070005 javascript runtime error file access is denied.
  • #763326
    Hello Amruta,

    Error 0x80070005 clearly show that file access is denied. It means the file which you are trying to access is not accessible by the user or the user don't have the rights to access that file. You must change the permissions for that file so the external resource can use or do action with that file.

    Change the permissions of that file for particular user or Everyone. It will start working for you.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763327
    i have granted all permissions to every user,still facing that problem.

  • #763328
    Hello Amruta,

    Share your code with us so that we can rectify the problem and will able to help you in easy way.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763329
    //**************** This fun to open file dialouge*********//

    function OpenDialog()
    {
    document.getElementById("radAsynFileDeficiency").click();

    }
    //****** To call On onChange Event Of File Upload**//
    function ClickButton()
    {
    document.getElementById("Button1").click();
    // return true;
    }

    <td class="spacing" style="text-align:center" >
    <asp:LinkButton ID="lnkUploadGuideline" runat="server" OnClientClick="javascript:return OpenDialog1()">Upload Response Document</asp:LinkButton>
    </td>
    <td class="spacing" style="display:none">
    <asp:FileUpload ID="radAsynFileGuidaline" runat="server" onchange="javascript:return ClickButton()" />
    <asp:HiddenField ID="hdnguidelineDocument" runat="server" />
    <asp:HiddenField ID="hdnGuidalinePath" runat="server" />
    <asp:HiddenField ID="hdnFileNameGiudeline" runat="server" />

    </td>
    <td style="display:none">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
    </td>


    //*********Server Side Code For button Click****//

    if (radAsynFileGuidaline.HasFile)
    {
    string UniqueFileName = "";
    string UploadPathResponse = "";
    UploadPathResponse = Server.MapPath(Request.ApplicationPath) + "\\NewFolderResponse\\";
    if (!Directory.Exists(UploadPathResponse))
    Directory.CreateDirectory(UploadPathResponse);
    UniqueFileName = DateTime.Now.ToString("HHmmssfff").Trim() + radAsynFileGuidaline.FileName;
    hdnguidelineDocument.Value = UploadPathResponse + UniqueFileName;
    //******************************************** save file in temperory folder and copy to the folder on server on submit//
    radAsynFileGuidaline.SaveAs(UploadPathResponse + UniqueFileName.ToString());
    hdnGuidalinePath.Value = UploadPathResponse + UniqueFileName.ToString();
    hdnFileNameGiudeline.Value = UniqueFileName.ToString();
    }

  • #763330
    Some of the Tips

    1. Use the client Id
    document.getElementById('<%=Button1.ClientID%>').click();

    2. Initially you are using "display:none". Can you check the controls are available in the view page source

    3. Why you are using "onchange" event in the FileUpload. Try to remove and check

    By Nathan
    Direction is important than speed

  • #763331
    thanks.i have checked the client id.and the controls are visible in page source.if i remove onchange event in file upload how will i call button click.

  • #763332
    Hello Amruta,

    The code you have provided. I have tried it. It is not working only means your dialogbox to select file is only not working.

    I have updated the code and now it is working.

    Updated code :

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type="text/javascript">

    function ClickButton() {
    document.getElementById("Button1").click();
    }
    </script>
    <style type="text/css">
    .style1
    {
    width: 100%;
    }
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td style="text-align:center; display:none;">
    <asp:LinkButton ID="lnkUploadGuideline" runat="server" OnClientClick="return OpenDialog1()">Upload Response Document</asp:LinkButton>
    </td>
    </tr>
    <tr>
    <td>
    <asp:FileUpload ID="radAsynFileGuidaline" runat="server" onchange="return ClickButton()" />
    <asp:HiddenField ID="hdnguidelineDocument" runat="server" />
    <asp:HiddenField ID="hdnGuidalinePath" runat="server" />
    <asp:HiddenField ID="hdnFileNameGiudeline" runat="server" />
    </td>
    </tr>
    <tr>
    <td style="display:none">
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </td>
    </tr>
    </table>
    </div>
    </form>
    </body>
    </html>

    protected void Button1_Click(object sender, EventArgs e)
    {
    if (radAsynFileGuidaline.HasFile)
    {
    string UniqueFileName = "";
    string UploadPathResponse = "";
    UploadPathResponse = Server.MapPath(Request.ApplicationPath) + "\\NewFolderResponse\\";
    if (!Directory.Exists(UploadPathResponse))
    Directory.CreateDirectory(UploadPathResponse);
    UniqueFileName = DateTime.Now.ToString("HHmmssfff").Trim() + radAsynFileGuidaline.FileName;
    hdnguidelineDocument.Value = UploadPathResponse + UniqueFileName;
    //******************************************** save file in temperory folder and copy to the folder on server on submit//
    radAsynFileGuidaline.SaveAs(UploadPathResponse + UniqueFileName.ToString());
    hdnGuidalinePath.Value = UploadPathResponse + UniqueFileName.ToString();
    hdnFileNameGiudeline.Value = UniqueFileName.ToString();
    }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    if (radAsynFileGuidaline.HasFile)
    {
    string UniqueFileName = "";
    string UploadPathResponse = "";
    UploadPathResponse = Server.MapPath(Request.ApplicationPath) + "\\NewFolderResponse\\";
    if (!Directory.Exists(UploadPathResponse))
    Directory.CreateDirectory(UploadPathResponse);
    UniqueFileName = DateTime.Now.ToString("HHmmssfff").Trim() + radAsynFileGuidaline.FileName;
    hdnguidelineDocument.Value = UploadPathResponse + UniqueFileName;
    //******************************************** save file in temperory folder and copy to the folder on server on submit//
    radAsynFileGuidaline.SaveAs(UploadPathResponse + UniqueFileName.ToString());
    hdnGuidalinePath.Value = UploadPathResponse + UniqueFileName.ToString();
    hdnFileNameGiudeline.Value = UniqueFileName.ToString();
    }
    }


    See the attached image. The file was uploaded successfully.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763335
    Thanks Nirav I have changed the code according to Your suggestion.Still getting same error.i am using IE 10.images are attached so that You can have better idea.

    Delete Attachment

  • #763336
    Hello Amruta,

    I have tried it in Google Chrome. It is working properly in chrome. You just check in Google Chrome and Mozilla Firefox. As i have used your code so it doesn't give me any error.

    So just try it and let me know if you still facing an error.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763337
    Hi Amrutha,

    As I Googled and found the common solution in all is, this is browser compatibility issue, it won't support IE older versions. Please confirm your browser, if that is IE I request you to please text it in different browser. Fileupload using javascript won't support in IE.

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments