Solved

How do I access the Request.Files from JavaScript?

Posted on 2010-08-19
4
847 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
4 Comments
 
LVL 3

Accepted Solution

by:
JtR earned 500 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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now