How to upload files to a remote webserver using FileUpload ?

Discussion in 'ASP .Net Web Controls' started by Prasath, Apr 18, 2006.

  1. Prasath

    Prasath Guest

    We are able to upload files to a localhost . How to make it working for a
    remote web server ?

    Prasath, Apr 18, 2006
    1. Advertisements

  2. To save a file from a client to a webserver, do the following:

    1. Include an HTML Input tag similar to the following in your .aspx file:

    <INPUT id="fileNewsNotes" type="file" size="50" name="fileNewsNotes"

    2. Use code such as the following to manipulate the PostedFile.FileName
    property and PostedFile.SaveAs method to save the file to the server:

    Dim dir As String() =

    Dim upfilename As String = dir(dir.GetUpperBound(0))

    fileNewsNotes.PostedFile.SaveAs(Server.MapPath("pdf/") & upfilename)

    PostedFile.FileName refers to the text that you see in the HTML input
    type="file" This string must be split, because you normally only want the
    name of the file, not the location on the client's machine. In the code I
    have above upfilename is the name of the file that is being submitted. In
    the last line, I call the SaveAs method which saves the file to the server.
    The parameter is the location that you want to save the file to. When
    specifying this parameter, it is usually best to use the Server.MapPath()
    method concatenated with the filename so that you can specify the directory
    as a relative directory. If you have any questions, feel free to ask. Good
    Nathan Sokalski, Apr 20, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.