我有这样的需求,要把各种类型的文件保存到数据库中,然后能够在WinForm中显示这些文件,请问如何实现?

解决方案 »

  1.   

    We have to  show different document by different application, So I think you must clear that which kind document you support at first, then show it by different application com.
      

  2.   

    如果是图片
    How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
    但是不同的文件需要调用不同的查看器,所以很难统一,
    不过使用浏览器控件能够查看一些常见的格式,
    2005下已经有了托管的浏览器控件,建议使用。
      

  3.   

    谁看文件编码呀,无非就是看文件名!数据库中留两个字段,一个是字符类型存文件名,另一个存二进制的文件内容。转换应该不是问题:
    public static bool CreateFileFromByteAarray(byte[] stream, string fileName)
    {
    try
    {
    FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
    fs.Write(stream, 0, stream.Length);
    fs.Close();
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.ToString());
    return false;
    }
    return true;
    }public static byte[] FileToByteAarray(string fileName)
    {
    try
    {
    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    int FileSize = Convert.ToInt32(fs.Length);
    byte[] stream = new byte[FileSize];
    fs.Read(stream, 0, FileSize); 
    return stream;
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.ToString());
    return null;
    }
    }
      

  4.   

    取得数据库二进制字段的文件内容后,如何在客户端显示呢。我知道System.Diagnostics.Process.Start("文件路径")可以自动调用与之相匹配的阅读器来显示指定文件路径的文件,但是现在取得的是stream,如何显示啊?