Results 1 to 3 of 3

Thread: How to upload files to a location specified?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    53

    Question How to upload files to a location specified?

    Hello, I'm having problems with some code. What I want to do is set up an HTML page which will allow a user to choose a file in a directory and upload it toa path specified on my server. Here is some code I came by and it allows me to choose a file but wont let me save it to a folder on my server. Any ideas will be much appreciated.

    <% @Page Language="C#" %>

    <html>
    <head>
    <title>File upload in ASP.NET</title>
    </head>
    <body bgcolor="#ffffff" style="font:8pt verdana;">
    <script language="C#" runat="server">
    void btnUploadTheFile_Click(object Source, EventArgs evArgs)
    {
    string strFileNameOnServer = txtServername.Value;
    string strBaseLocation = "c:\\temp\\";

    if ("" == strFileNameOnServer)
    {
    txtOutput.InnerHtml = "Error - a file name must be specified.";
    return;
    }

    if (null != uplTheFile.PostedFile)
    {
    try
    {
    uplTheFile.PostedFile.SaveAs(strBaseLocation+strFileNameOnServer);
    txtOutput.InnerHtml = "File <b>" +
    strBaseLocation+strFileNameOnServer+"</b> uploaded successfully";
    }
    catch (Exception e)
    {
    txtOutput.InnerHtml = "Error saving <b>" +
    strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
    }
    }
    }
    </script>

    <table>
    <form enctype="multipart/form-data" runat="server">
    <tr>
    <td>Select file:</td>
    <td><input id="uplTheFile" type=file runat="server"></td>
    </tr>
    <tr>
    <td>Name on server:</td>
    <td><input id="txtServername" type="text" runat="server"></td>
    </tr>
    <tr>
    <td colspan="2">
    <input type=button id="btnUploadTheFile" value="Upload"
    OnServerClick="btnUploadTheFile_Click" runat="server">
    </td>
    </tr>
    </form>
    </table>

    <span id=txtOutput style="font: 8pt verdana;" runat="server" />

    </body>
    </html>

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: How to upload files to a location specified?

    I put the answer on your other thread.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    53

    Question Re: How to upload files to a location specified?

    Quote Originally Posted by sevenhalo
    I put the answer on your other thread.


    What other thread?

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