ASP.NET - Uploading files to the server

Discussion in 'Forum for discussion of ANTICHAT' started by Dracula4ever, 28 Feb 2007.

  1. Dracula4ever

    Dracula4ever Elder - Старейшина

    Joined:
    8 May 2006
    Messages:
    418
    Likes Received:
    183
    Reputations:
    26
    A while ago I answered a question about uploading files from an ASP.net application on walla.co.il … So here is the tip:

    To let your users upload files from their computer to the server you can use a great contol called “FileUpload” control.

    To use the control, just put the code below into the POST event and the file that the user asked to upload will be uploaded to the server: (Note: oFile is the FileUpload control)

    PHP:
    if (oFile.PostedFile != null)
    {
    string fullFileName oFile.PostedFile.FileName//getting the path
    string fileName System.IO.Path.GetFileName(fullFileName); //getting the 
    filenameoFile.PostedFile.SaveAs(Server.MapPath(string.Empty) + \\” fileName); //saving the file on the demand directory on the server file system
    }
    Note: this code checks if a file was really sent before trying to save it.
     
    #1 Dracula4ever, 28 Feb 2007
    Last edited: 3 Mar 2007