FILESTREAM - 使用 SQLFileStream 读取存储在文件系统中的文档

发布于 2024-12-17 12:48:17 字数 696 浏览 2 评论 0原文

我将 Filestream 文档保存在 NTFS 中。每次我尝试使用下面的块访问它们时,我都会在 Image.FromStream 行上收到“参数无效”错误消息。这和FS文件夹中存储的文件有什么关系吗?或者我的参数缺少什么? 有没有办法查看文件夹中的文件以验证它们的格式是否正确?

private static Image LoadPhotoImage(string filePath, byte[] txnToken)
    {
        Image photo;
        try
        {
            using (SqlFileStream sfs =
              new SqlFileStream(filePath, txnToken, FileAccess.Read))
            {
                photo = Image.FromStream(sfs,false);
                sfs.Close();
            }

            return photo;
        }
        catch (ArgumentException ae)
        {
            System.Diagnostics.Debug.WriteLine(ae.Message);
            return null;
        }
    }

I saved Filestream documents in the NTFS. Each time I attempt to access them using the block below, I get the 'Parameter Is Not Valid' error message on the Image.FromStream line. Would this have anything to do with the stored files in the FS folder? Or are my parameters missing something?
Is there a way to view the files in the folder to verify they are well formed?

private static Image LoadPhotoImage(string filePath, byte[] txnToken)
    {
        Image photo;
        try
        {
            using (SqlFileStream sfs =
              new SqlFileStream(filePath, txnToken, FileAccess.Read))
            {
                photo = Image.FromStream(sfs,false);
                sfs.Close();
            }

            return photo;
        }
        catch (ArgumentException ae)
        {
            System.Diagnostics.Debug.WriteLine(ae.Message);
            return null;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万人眼中万个我 2024-12-24 12:48:17

您不能将 SqlFileStream 用于此目的,根据 MSDN文档

“SqlFileStream 类用于处理通过 SQL Server 2008 数据库中的 FILESTREAM 属性存储的 varbinary(max) 数据。”

只需使用 Image.FromFile 加载图像即可。

You can't use SqlFileStream for this purpose, per the MSDN Documentation:

"The SqlFileStream class is used to work with varbinary(max) data stored with the FILESTREAM attribute in a SQL Server 2008 database."

Just use Image.FromFile to load the image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文