http://aspalliance.com/das/datagridimages.aspx

解决方案 »

  1.   

    我的做法是把数据库上的文件下载到客户端的一个临时文件中,再用ie打开。但客户端必须装有Word才能打开。例:
        Private Function 文件装载(ByVal LID As Integer) As String
            Dim i, j, k As Integer
            Dim b_file, c_file, s_file As String
            Dim objDS As Byte()
            Dim c_path As String = MapPath("kycrmtemp")
            Dim LFile As IO.FileStream
            For i = 0 To DataSet41.Tables("附件").Rows.Count - 1
                With DataSet41.Tables("附件").Rows(i)
                    If .Item("ID") = LID Then
                        b_file = Trim(.Item("格式"))
                        Do
                            k = Int(Rnd() * 100000)
                            c_file = c_path & "\" & CStr(k) & "." & b_file
                            s_file = CStr(k) & "." & b_file
                            If Not IO.File.Exists(c_file) Then Exit Do
                        Loop
                        Try
                            objDS = .Item("文件")
                            LFile = New IO.FileStream(c_file, IO.FileMode.OpenOrCreate)
                            LFile.Write(objDS, 0, objDS.Length)
                            LFile.Close()
                        Catch
                        End Try
                        Exit For
                    End If
                End With
            Next
            文件装载 = s_file
        End Function
      

  2.   

    现在我已经能够上传word文件,并从数据库读取后显示在页面里.
    但是新问题就出现了:
    1.我如何显示在一个iframe里?
    2.而经过修改的文件我又如何能在同一个网页中直接回传到数据库?
    不知道能否解决?
      

  3.   

    能用的代码决不自己独享
    上传部分:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim fs As System.IO.Stream
            Dim n, m As Integer
            Dim cs() As Byte
            Dim dd As New HtmlInputFile()
            dd.ID = "dd"
            TextBox1.Text = dd.PostedFile.ContentLength
            n = dd.PostedFile.ContentLength
            ReDim cs(n)
            fs = dd.PostedFile.InputStream
            fs.Read(cs, 0, n)
            '        dd.PostedFile.SaveAs("c:\ddd.nn")
            SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@f", System.Data.SqlDbType.Image, n, ParameterDirection.Input, False, 0, 0, "f", DataRowVersion.Current, cs))
            SqlCommand1.CommandText = "Insert into table1(f) values(@f)"
            fs.Close()
            SqlCn.Open()
            SqlCommand1.ExecuteNonQuery()
            SqlCn.Close()    End Sub
      

  4.   

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim fs As System.IO.Stream        '使用http的io.stream的方法上传文件
            Dim n, m As Integer
            Dim cs() As Byte                  '用来临时存储文件的数组
            n = dd.PostedFile.ContentLength   '取得上传文件的长度
            ReDim cs(n)                       '重定义数组的大小文文件长度 
            fs = dd.PostedFile.InputStream     
            fs.Read(cs, 0, n)                 '用inputstream的方法读取文件到数组 
            SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@f", System.Data.SqlDbType.Image, n, ParameterDirection.Input, False, 0, 0, "f", DataRowVersion.Current, cs))    '这一步是关键参数不能出错.设置sql语句的参数   
            SqlCommand1.CommandText = "Insert into table1(f) values(@f)" '上传语句
            fs.Close()                   '下面的我就不解释了.
            SqlCn.Open()
            SqlCommand1.ExecuteNonQuery()
            SqlCn.Close()
        End Sub
    等我重装系统后把下载部分的代码也贴出来共享.
      

  5.   

    上传到数据库中的word文件,从数据库读取后如何显示在网页内?
      

  6.   

    下载部分的:
     SqlCommand1.CommandText = "select f from table1 where (id=2)这里id你自己设置
            Dim sqlr As SqlClient.SqlDataReader
            Dim fs As System.IO.Stream
            Dim cs() As Byte
            fs = Response.OutputStream()
            SqlConnection1.Open()
            sqlr = SqlCommand1.ExecuteReader
            If sqlr.Read Then
                Response.ContentType = "Application/msword"‘这句话千万不能少
                'Response.Clear()
                cs = sqlr("f")
                sqlr.GetBytes(0, 0, cs, 0, UBound(cs))
                fs.Write(cs, 0, UBound(cs))
                fs.Close()
            End If
            sqlr.Close()
            SqlConnection1.Close()
    ok,你已经能在ie中打开这个word文件了。
    不过在线编辑后还是要存盘才能上传到数据苦中。补充如果上传页面编译是提示没有设置到实例删除下面两句话
            Dim dd As New HtmlInputFile()
            dd.ID = "dd"
      

  7.   

    在线编辑器:
    http://www.milujie.com/new/web/edit.htm
      

  8.   

    HTML在线编辑器的调用方法 http://www.csdn.net/develop/article/15/15214.shtm
    另一个在线编辑器:http://www.5aijie.com/html/jianzhan/2.htm
      

  9.   

    我原来的做法是:保存文档的字段是image类型。我上传的到服务器端后,将文件二进制化后存储到数据库表中,并记录二进制化之前的文件类型。
    以后读出时,根据原来的类型,先修改浏览器显示类型:response.contenttype
    然后,将保存文件的字段值response.binarywrite就够了!但我发现我调试过同个局域网内的十多台机器,当然每个都装有office 2000。可是有少量机器是打开失败的,会有什么警告框,什么内存不足只类的话。但大部分机器打开正常!这个做法,可以将很多种类型的文件保存为二进制,然后再输出。