Solved

How do I access the Request.Files from JavaScript?

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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)

920 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

15 Experts available now in Live!

Get 1:1 Help Now