上传文件到数据库报错:未找到路径
我用ASP.Net做的网站,客户要能上传文件到服务端的数据库里,
aspx里是用这个选择文件的:
<input type="file" size="40" name="edConFile" id="edConFile" width="100px" runat="server">
VB代码如下:
Private Sub BtnSaveFile_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSaveFile.ServerClick
Dim strFileName As String = G_objService.SB_MyTrim(edConFile.Value)
If strFileName = "" Then
Me.RegisterStartupScript("MyShowConAttachError", "<script>alert(""请选择要保存的文件!"")</script>")
Exit Sub
End If
Dim f As New System.IO.FileInfo(strFileName)
Dim fs As System.IO.FileStream
fs = f.OpenRead
Dim b(fs.Length) As Byte
fs.Read(b, 0, fs.Length)
Dim strSQL As String
Dim myDataAccess As New DataAccess
With myDataAccess
.OpenConn()
If lConAttachID < 0 Then
strSQL = "insert into SvcConAttach(ConBillID,FileName,FileData,MakingPersonNo) Values(-1,'" + strFileName + "',@File,'admin')"
Else
strSQL = "update SvcConAttach set FileData = @File where ConAttachID=" + lConAttachID
End If
.DWCommSQL.CommandText = strSQL
Dim spFile As New SqlClient.SqlParameter("@File", SqlDbType.Image)
spFile.Value = b
.DWCommSQL.Parameters.Add(spFile)
.DWCommSQL.ExecuteNonQuery()
End With
End Sub
其中myDataAccess是一个读写数据库的类,没问题。我在本地调试时,能正常保存,但把网站发布到服务器上后运行就报错了:
未找到路径"E:\My Documents\桌面\Loadup_plan.txt"的一部分
后反复调试发现,选择的文件必须是网站所在硬盘上存在的文件,就是说,以上代码只能读取服务器端的文件,怎么写能保存客户端的文件呢?
在线等待,请大侠指点!