如何运行存储在Sql中的二进制数据字段 [英] How Can I Run Binary Data Field Stored In Sql

查看:104
本文介绍了如何运行存储在Sql中的二进制数据字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
i将字符串转换为byte []如下:

我的字符串是图像代码:



byte [] attachment = Convert.FromBase64String(my string);



我在二进制字段中保存sql server中的附件。

当我想要的时候在Windows中运行此文件,我无法在Windows照片查看器中看到图像。



i以这种方式运行文件:



附件AttObj = MyDB.Attachment.Where(a => a.AttachmentId == ID).First();



if(AttObj.Attachment1 != null)

{

流程proc =新流程();



string FileTmpDircetion =目录。 CreateDirectory(我的临时目录);

FileTmpDircetion = System.IO.File.WriteAllBytes(FileTmpDircetion,AttOb.file);



proc。 StartInfo.FileName = FileTmpDircetion;

proc.StartInfo.UseShellExecute = true;

proc.Start();

}





s请注意:

Windows照片浏览器无法打开此图片,因为该文件似乎已损坏,损坏或太大



请帮帮我

解决方案

http://www.aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASPNet.aspx [<一个href =http://www.aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASPNet.aspx\"target =_ blanktitle =New Window> ^ ]

Hi i convert a string to byte[] as following:
my string is a image code:

byte[] attachment = Convert.FromBase64String(my string);

I save attachment in sql server in a binary field.
when i want to run this file in windows , i cant see image in windows photo viewer.

i run file in this way:

Attachment AttObj = MyDB.Attachment.Where(a => a.AttachmentId == ID).First();

if (AttObj.Attachment1 != null)
{
Process proc = new Process();

string FileTmpDircetion = Directory.CreateDirectory(my temp directory);
FileTmpDircetion = System.IO.File.WriteAllBytes(FileTmpDircetion, AttOb.file);

proc.StartInfo.FileName = FileTmpDircetion ;
proc.StartInfo.UseShellExecute = true;
proc.Start();
}


it shows a message that :
"Windows photo viewr cant open this picture because the file appears to be damaged,corrupted or too large"

please help me

解决方案

http://www.aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASPNet.aspx[^]


这篇关于如何运行存储在Sql中的二进制数据字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆