我用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"的一部分
后反复调试发现,选择的文件必须是网站所在硬盘上存在的文件,就是说,以上代码只能读取服务器端的文件,怎么写能保存客户端的文件呢?在线等待,请大侠指点!
<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"的一部分
后反复调试发现,选择的文件必须是网站所在硬盘上存在的文件,就是说,以上代码只能读取服务器端的文件,怎么写能保存客户端的文件呢?在线等待,请大侠指点!
解决方案 »
- ascx页面中调用类库中的类
- 哀悼地震,请问网页的灰暗效果技术上如何实现?
- 百分急求解决----Object reference not set to an instance of an object
- 江湖救急:如何让 DropDownList 绑定到不同的数据源?
- 2007年了,水晶报表导出Excel还有边框吗
- ACCESS一个简单问题
- masterpage的问题(第一次发贴!)
- 一个奇怪得异常错误,由程序代码引发,大家来讨论一下!
- 回个选择题的选择,怎样随机排列?
- webform treeview怎么取当前节点
- 求助This type of page is not served.
- 搜索出错,dt.Rows[0][0]
Dim f As New System.IO.FileInfo(strFileName)
Dim fs As System.IO.FileStream
……
太谢谢了,我要的就是这个!
太谢谢了,我要的就是这个!