为了显示Byte[]
数据GridView
,我使用了下面的代码
DataColumn dc4 = new DataColumn("Bytes", typeof(string));
我想知道它是否正确?
完整代码如下:
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
DataColumn dc4 = new DataColumn("Bytes", typeof(string));
dt = new DataTable();
DataColumn dc1 = new DataColumn("File Name", typeof(string));
DataColumn dc2 = 1new DataColumn("File Size", typeof(string));
DataColumn dc3 = new DataColumn("Content Type", typeof(string));
DataColumn dc4 = new DataColumn("Bytes", typeof(string));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dr = dt.NewRow();
dr["File Name"] = FileName;
if (size > 0)
dr["File Size"] = size.ToString() + " KB";
else
{ dr["File Size"] = fileObj.Length.ToString() + " Bytes"; }
dr["Content Type"] = contenttype;
dr["Bytes"] = bytes;
dt.Rows.Add(dr);
GridViewEfile.DataSource = dt;
GridViewEfile.DataBind();