后续代码如何受到影响?有人告诉我!! [英] how does follwing code affected ? Somebody tell me !!

查看:113
本文介绍了后续代码如何受到影响?有人告诉我!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个文件上传控制页面,用于将'nvarchar(max)'类型转换为'bytes'!

它现在正在工作!

但是我想了解更多关于这个代码转换的信息!



如果我想将转换varbinary(max)转换为字节,应该怎么做?我这样做?

I have created a page for file upload control for converting 'nvarchar(max)' type to 'bytes' !
Its working now !
but I want to know more about this code convertion !

If I want to make conversion varbinary(max) to bytes , what should I do ?

string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string ext = Path.GetExtension(filename);
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".PNG" || ext == ".JPG" || ext == ".JPEG" || ext == ".gif" || ext == ".GIF")
{
    Stream fs = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(fs);
    Byte[] bytes = br.ReadBytes((Int32)fs.Length);
    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
    Label1.Text = "Data stored successfully !!!!!";
}
else
{
    Response.Write("<script>alert('unsupported format of photo file');</script>");
}





提前致谢!



Thanks in advance !

推荐答案

1 。将图像的字节保存为Base64编码字符串是WTF。数据库引擎提供二进制列类型。更好地使用它们。

2.要从这种错误存储的图像中获取字节,请使用Convert.FromBase64String(您的字符串)。
1. Saving an image's bytes as a Base64 encoding string is a WTF. Database engines offer binary column types. Better use them.
2. To get the bytes from such a "wrongly" stored image, use Convert.FromBase64String(your string).


这篇关于后续代码如何受到影响?有人告诉我!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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