Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    74
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Upload File to Web-Server

    I have no clue why the following isn't working, maybe someone could take a look.

    HTML SOURCE CODE:
    <form id="Form1" style="TEXT-ALIGN: center" method="post" encType="multipart/form-data" runat="server">
    <INPUT id="fileUpdate" name="fileUpdate" type="file" runat="server"><br>
    <INPUT id="subUpdate" name="subUpdate" value="Upload" type="submit" runat="server"><br>
    </form>

    C# SOURCE CODE:
    private void subUpdate_ServerClick(object sender, System.EventArgs e)
    {
    if( ( fileUpdate.PostedFile != null ) && ( fileUpdate.PostedFile.ContentLength > 0 ) )
    {
    string fn = System.IO.Path.GetFileName(fileUpdate.PostedFile.FileName);
    string SaveLocation = Server.MapPath("Data") + "\\" + fn;

    try
    {
    fileUpdate.PostedFile.SaveAs(SaveLocation);
    Response.Write("The file has been uploaded.");
    }

    catch ( Exception ex )
    {
    Response.Write("Error: " + ex.Message);
    }
    }
    else
    {
    Response.Write("Please enter a file to upload.");
    }
    }

    I created a folder called [Data] in my \wwwroot\project folder, I expected the code to take any <4meg file when browsing and upload it to that folder (and post the corresponding message via the Response.Write).

    However I find that a) I get no Messages (Response.Write is supposed to display a message no?) and b) the file is not uploaded after pressing the UPLOAD button, the browse box is cleared and the page seems to refresh.. Still no messages.

    Any clues? (I am still kind of new at all this ASP stuff)
    Could it be like folder permissions? (wouldn't that give me access denied?)

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I dug this up from my archive, you might want to check out.
    Attached Files Attached Files
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    And here is a pure ASP (i.e. no components) resource for letting the user upload a file which is something that was unfortunately not built into ASP:

    ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
    http://aspzone.com/posts/160.aspx
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Updated (corrected) link:

    ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
    http://aspzone.com/articles/160.aspx
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips


  •  

    Posting Permissions

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