Solved

How do I access the Request.Files from JavaScript?

Posted on 2010-08-19
4
849 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

776 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