?
Solved

How do I access the Request.Files from JavaScript?

Posted on 2010-08-19
4
Medium Priority
?
855 Views
Last Modified: 2012-08-14
This is a real newbe question.  I have an ASP.Net page where I am calling the jQuey dialog from a JavaScript function. Each time the user selects a file I would like to add the file to a simple table on the page.

If I understand the jQuery function correctly it is adding the selected file to Request.Files.  I can access this from VB.Net or C#.  

Is there any way to access the Request object from JavaScript?

 <script type="text/javascript">

        // jQuery Dialog
        $(function () {
            $("#dialog").dialog({
                bgiframe: true,
                height: 140,
                modal: true,
                autoOpen: false,
                resizable: false
            })
        });

        function GetCsvFile() {

            // jQuery call to prompt user for a file
            jQuery('#dialog').dialog('open');

            // Want to list all files selected to a simple table on the page...

            
        }

                <div id="dialog" title="Add CSV File">
                    <form action="/File.mvc/Upload" enctype="multipart/form-data" method="post">
                    <p>
                        <input type="file" id="fileUpload" name="fileUpload" size="23" /></p>
                    <p>
                        <input type="button" id="addFile" name="addFile" value="Add File" onclick="AddSmsCsvToList()" />   <input type="submit" value="Upload" /> </p>
                   </form>
                </div>

Open in new window

0
Comment
Question by:MDKIMZEY
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
JtR earned 2000 total points
ID: 33478887
The file is uploaded via webbrowser, not via Javascript. So the only thing you can get via Javascript is the filename of the input field that you used for selecting the file.

For example if you have an uploader with a progress bar than it checks (on a hidden ajax channel) and a corresponding script on the webserver how many bytes are already transfered.

you can access the file on the webserver only.
accessing local files via javascript is not possible (at least not without reconfiguring the security policy of your webbrowser) - so it is not practically for a "public application" as the user have to configure their browsers to a less secure level.
0
 
LVL 3

Assisted Solution

by:JtR
JtR earned 2000 total points
ID: 33479002
I red my answer and was not sure if you would understand what i mean :D

1. you can only access a file upload on a webserver. the upload managers just FAKING to know how many bytes are uploaded. in real they ask your webserver.

2. you could theoretically read the file whose name is given in the file upload input box, BUT it is not a good idea because you needed to level down your browsers security to allow local file access.
0
 

Author Closing Comment

by:MDKIMZEY
ID: 33486783
JtR,

Thanks much - I have worked through the issues.  
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question