infinitizon
MIS
Hi all, I have a site that has an upload page.
The idea is that users should be able to upload different files (Files are stored on the database).
I have tested from VS 2008 and everything seems to be working fine there. Now, when I upload the site to my remote server, and I test the upload there, it still works well (I can upload on the remote server).
The problem is that when I login from my local machine on the hosted site and try to upload, I get an error.
Basically, I cant upload from my local machine to the remote server.
I use thesame database (sqlserver2008) both for testing and remote hosting.
Note: remote server is another computer in the network (Intranet).
What can I do.
Code
code behind
Help please!
____________________
Men put up a strong face just to cover their weaknesses...good!
But a smile makes them live longer....
Which would you choose?
Think about it.
The idea is that users should be able to upload different files (Files are stored on the database).
I have tested from VS 2008 and everything seems to be working fine there. Now, when I upload the site to my remote server, and I test the upload there, it still works well (I can upload on the remote server).
The problem is that when I login from my local machine on the hosted site and try to upload, I get an error.
Basically, I cant upload from my local machine to the remote server.
I use thesame database (sqlserver2008) both for testing and remote hosting.
Note: remote server is another computer in the network (Intranet).
What can I do.
Code
Code:
<asp:FileUpload ID="myFile" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload New" />
Code:
Private connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
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)
'First save to Files directory
'Dim dirPath As String = AppDomain.CurrentDomain.BaseDirectory + "Files"
'myFile.PostedFile.SaveAs(dirPath & "\" & strFileNameOnly)
Dim fs As FileStream = New FileStream(strFileNamePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
br.Close()
fs.Close()
'insert the file into database
Dim strQuery As String = "insert into Intranet_File_Table(docNo, ContentType, fileName, fileDesc,uploadDate,"
strQuery &= "revisedDate, uploadByUser,modifiedByUser , fileBlobForm)"
strQuery &= "values (@docNo, @ContentType,@fileName,@fileDesc,@uploadDate,@revisedDate,@uploadByUser,@modifiedByUser,@fileBlobForm)"
Dim cmd As SqlCommand = New SqlCommand(strQuery)
cmd.Parameters.AddWithValue("@docNo", txtDocType.Text)
cmd.Parameters.AddWithValue("@ContentType", myFile.PostedFile.ContentType)
cmd.Parameters.AddWithValue("@fileName", strFileNameOnly)
cmd.Parameters.AddWithValue("@fileDesc", txtDesc.Text)
cmd.Parameters.AddWithValue("@uploadDate", Date.Now)
cmd.Parameters.AddWithValue("@revisedDate", Date.Now)
cmd.Parameters.AddWithValue("@uploadByUser", My.User.Name)
cmd.Parameters.AddWithValue("@modifiedByUser", My.User.Name)
cmd.Parameters.AddWithValue("@fileBlobForm", bytes)
lblMsg.Text = "File Upload Success.<br />"
lblMsg.Text &= "Content type: " & myFile.PostedFile.ContentType & "<br />"
lblMsg.Text &= "File size: " & CStr(myFile.PostedFile.ContentLength) & " bytes<br />"
lblMsg.Text &= "File Name: " & strFileNameOnly
InsertUpdateData(cmd)
updateGridView()
Else
lblMsg.Text = "You did not specify a file to upload"
End If
End Sub
Public Function InsertUpdateData(ByVal cmd As SqlCommand) As Boolean
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()
Dim con As New SqlConnection(strConnString)
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
cmd.ExecuteNonQuery()
Return True
Catch ex As Exception
Response.Write(ex.Message)
Return False
Finally
con.Close()
con.Dispose()
End Try
End Function
Help please!
____________________
Men put up a strong face just to cover their weaknesses...good!
But a smile makes them live longer....
Which would you choose?
Think about it.