Uploading a file on a remote server.

  • Thread starter Thread starter egsdar
  • Start date Start date
E

egsdar

Hello, I have already created the script to upload a file (but locally) and
I'd like to upload it on my remote server, how can I do this?

this is my code:



Sub Upload(ByVal Source As Object, ByVal e As EventArgs)

If Not (myFile.PostedFile Is Nothing) Then

Dim intFileNameLength As Integer

Dim strFileNamePath As String

Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)

strFileNamePath = MyFile.PostedFile.FileName

intFileNameLength = Instr(1, StrReverse(strFileNamePath), "\")

strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) -
intFileNameLength) + 2)

Dim nombrearchivo As String

nombrearchivo = "C:\Inetpub\wwwroot\Proyectos\Documentos\" & strFileNameOnly

myFile.PostedFile.SaveAs(nombrearchivo)

lblMsg.Text = "El archivo se subió con exito."

Dim sqlConn As System.Data.SqlClient.SqlConnection

Dim sqlCmd As System.Data.SqlClient.SqlCommand

Dim strConnection, resul As String

strConnection =
ConfigurationManager.ConnectionStrings("SIPConnectionString").ConnectionString

sqlConn = New System.Data.SqlClient.SqlConnection(strConnection)

sqlCmd = New System.Data.SqlClient.SqlCommand("Insert into
documentos(idpropuesta, nombre) values(" & Request.QueryString("mivar") & ",
'" & nombrearchivo & "')", sqlConn)

sqlConn.Open()

resul = sqlCmd.ExecuteNonQuery

sqlConn.Close()

GridView1.DataBind()

End If

End Sub





With this current code is displaying an error :

Cannot find the current path "c:\inetpub\wwwroot\Sip\documents"
 
your server and client don not agree on the upload format. the server
code is expecting a multipart/form-data post of the file (base54 encoded
with boundary tags) and the client is just streaming a file.

i'd change the client code to do a multipart post. look at the w3c spec
for details on posting a file inside a html form. basically set the
content-type to "multipart/form-data", define a mime boundary, then
build a standard mime message. the boundary should be a unique 42 byte
string.

Request.ContextType = "multipart/form-data; boundary=" + myBoundary;
then output for each form field:

<boundary><lf>
Content-Disposition: form-data; name="<fieldname>"<lf>
<lf>
<value><lf>
<boundary><lf>

for each text file:

<boundary><lf>
Content-Disposition: form-data; name="<fieldname>";
filename="<filename>"<lf>
Content-Type: text/plain<lf>
<lf>
<the text of the file><lf>
<boundary><lf>

for each binary file

<boundary><lf>
Content-Disposition: form-data; name="<fieldname>";
filename="<filename>"<lf>
Content-Type: application/octet-stream<lf>
<lf>
<the binary file data><lf>
<boundary><lf>

-- bruce (sqlwork.com)
 
Back
Top