CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    executing javascript function causes unwanted directory listing

    I have an ASP.NET app (c# codebehind) in which I alow the user to browse for a file using <input type=file>. Clicking on another link calls a javascript function which is to open the designated file and read its contents into a textbox. I am pretty sure I can do all of that without dificulty... BUT for reasons that I don't understand, simply calling this javascript function will result in a directory listing (or attempted directory listing)... In fact, I even tried putting a return statement at the very beginning of the function so that none of the other code will execute, and even that causes this stupid directory listing...

    How can I make this directory listing go away???

    Here is a snippet of the HTML code:
    Code:
    <P>Select a file<br>
    <input id="File1" type="file" size="40" name="File1">&nbsp;
    <a href="" onclick="Preview()">Preview the file contents</a></P>
    
    <P><STRONG>File contents:</STRONG><BR>
    <asp:textbox id="TextBox3" runat="server" Height="74px" Width="554px"></asp:textbox></P>
    Here is the source of the javascript function:
    Code:
    function Preview()
    {
    	try
    	{
    		// get the filename...
    		var file_val = eval("document.Form1.File1");
    		var strFileName = file_val.value;
    
    		// open the file, read it, put it in the text box...
    		var fso = new ActiveXObject("Scripting.FileSystemObject");
    		var f = fso.OpenTextFile(strFileName, 1);
    		var str = f.ReadAll();
    		//alert(str);
    		document.Form1.TextBox3.value = str;
    					
    		f.Close();
    	}
    	catch (Exception)
    	{
    		alert("Cannot open file :( " + Exception.message);
    	}
    }

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: executing javascript function causes unwanted directory listing

    Is the actual script being run on the client-side or server-side?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured