Results 1 to 5 of 5

Thread: Open file Dialog in ASP.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    14

    Open file Dialog in ASP.NET

    I need to produce an open file dialog much like the Windows' Common Dialog of the past in an ASP.NET application, however, I can't find anything in the VB documentation, as the System.Web namespace has nothing to produce, nor does a search on the web.

    Am I headed in the wrong direction trying to use VB to produce the dialog? Should I be using another technology?

    Still befuddled by this silly web stuff,
    -Chris

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    You design it using html forms..like a select box then use the system.io stuff to list files located on the web server..no you cant do this nice dialog like windows apps..You need to learn that web apps are severly different than windows desktop apps.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    14
    OK, so break it down a little for me please. Let's take Web Hosting Provider's Web Upload utilities for example - most have a table of 5 text boxes for file names to upload and 5 Browse buttons, each browse button popping up something which looks similar to a common dialog, and when a file is selected, the full file name as assigned as the textbox's text. (note that I'm looking for the end user's file system, not the web servers.)

    How exactly does a web programmer call the dialog box? From how I interpreted your response, I'm supposed to use a similar solution to the old VB FileBox / ListBox / DirBox controls... and those weren't very good.

  4. #4
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Originally posted by kcornell
    How exactly does a web programmer call the dialog box? From how I interpreted your response, I'm supposed to use a similar solution to the old VB FileBox / ListBox / DirBox controls... and those weren't very good.
    The sample below shows the File dialog you desire but there are major differences from the traditional desktop app usage.

    Even if all you want is the filename....the entire file is uploaded to the server BEFORE you can do anything. You can't just get the file name or such, unless you write some client-side javascript to access the textbox after the browse is done....not sure if that's even possible tho. I suck at javascript.

    Also, IIRC, you have no control over the default folder or file type shown the user.

    Cander is right.....unless you want to drive your self crazy.....you need to forget what you know about Windows desktop apps. Hacks withstanding, you have no control over the clients system. You can't browse it, search it, anything. HTML/JavaScript have severe limits for security reasons and that's all you really have on the client.

    Code:
    <%@ Page debug="true" %> 
    
    <script language="c#" runat="server"> 
    
    void Page_Load(Object sender, EventArgs e) 
    {
        if (Page.IsPostBack)
        {
            SaveImages();
        } 
    }
    
    System.Boolean SaveImages()
    {
    System.Web.HttpFileCollection colFiles = System.Web.HttpContext.Current.Request.Files; 
    System.Text.StringBuilder strMessage;
    strMessage = new System.Text.StringBuilder("Files Uploaded:<br><br>");
    System.Int32 intFileCntr;
    
    try 
    {
    
        for (intFileCntr = 0; intFileCntr < colFiles.Count; intFileCntr++)
        {
    
            System.Web.HttpPostedFile objCurrentFile = colFiles.Get(intFileCntr); 
            System.String strCurrentFileName;
            System.String strCurrentFileExtension; 
    
            strCurrentFileName = System.IO.Path.GetFileName(objCurrentFile.FileName); 
    
            if(strCurrentFileName != "")
            { 
    
                strCurrentFileExtension = System.IO.Path.GetExtension(strCurrentFileName); 
    
                if (strCurrentFileExtension == ".gif" || strCurrentFileExtension == ".jpg")
                {
    
                    objCurrentFile.SaveAs(strCurrentFileName); 
    
                    strMessage.Append(strCurrentFileName + " successfully uploaded.<BR>"); 
                }
                else
                {
                    strMessage.Append(strCurrentFileName + " <font color='red'>failed!! Only .gif and .jpg images allowed!</font> <BR>"); 
                } 
            } 
        } 
    
        Label1.Text = strMessage.ToString(); 
        return true; 
    }
    catch (System.Exception Ex)
    { 
        Label1.Text = Ex.Message; 
        return false; 
    }
    }
    
    </script> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
    <HTML> 
    <HEAD> 
    <title>::: UPLOAD SAMPLE ::: </title> 
    </HEAD> 
    <body> 
    <center> 
    <form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data"> 
    <h3>Multiple File Upload Example</h3> 
    <P> 
    <INPUT type="file" runat="server" size="50" ID="File1" NAME="File1"></P> 
    <P> 
    <INPUT type="file" runat="server" size="50" ID="File2" NAME="File2"></P> 
    <P> 
    <INPUT type="file" runat="server" size="50" ID="File3" NAME="File3"></P> 
    <P> 
    <INPUT type="file" runat="server" size="50" ID="File4" NAME="File4"></P> 
    <P> 
    <INPUT type="file" runat="server" size="50" ID="File5" NAME="File5"></P> 
    <P><STRONG>:: </STRONG> 
    <asp:LinkButton id="LinkButton1" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small">Upload Images</asp:LinkButton> <STRONG>:: 
    </STRONG> <A href="java script:document.forms[0].reset()" id="LinkButton2" style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana"> 
    Reset Form</A> <STRONG>::</STRONG></P> 
    <P> 
    <asp:Label id="Label1" runat="server" Font-Names="verdana" Font-Bold="True" Font-Size="XX-Small" Width="400px" BorderStyle="None" BorderColor="White"></asp:Label></P> 
    <P> </P> 
    </form> 
    </center> 
    </body> 
    </HTML>

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    14
    A little closure for the topic:

    I found it a lot easier to use the HTML File Control, as it's Value property allowed the exact same thing as a text box's text property that was holding a file name... or, for those w/o VS.net:

    Code:
    <input type="file" id="(id here)">
    Light years behind technology, but eh, you gotta start somewhere.

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