How to upload files to a remote webserver using FileUpload ?

P

Prasath

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

Thanks
 
N

Nathan Sokalski

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"
runat="server">


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() =
fileNewsNotes.PostedFile.FileName.Split("\".ToCharArray())

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
Luck!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top