SqlConnection conn = new SqlConnection("server=(local);database=stock;uid=sa;pwd=");
SqlCommand sel = new SqlCommand("select Doc from tblBooksUpload where DocID=4", conn);
conn.Open();
SqlDataReader dr = sel.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.BinaryWrite((byte[])dr["Doc"]); }
dr.Close();
conn.Close()
这段代码输出原本是图片格式存入的没问题,但换成txt,doc的再绑定image就出现乱码
SqlCommand sel = new SqlCommand("select Doc from tblBooksUpload where DocID=4", conn);
conn.Open();
SqlDataReader dr = sel.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.BinaryWrite((byte[])dr["Doc"]); }
dr.Close();
conn.Close()
这段代码输出原本是图片格式存入的没问题,但换成txt,doc的再绑定image就出现乱码
要对得上号才不乱码。
是不是输出时要进行进一步处理?
还是不应该全绑定到image控件上?
Image控件只能认识图片,其他的你得SHELL对应的程序去打开
http://dotnet.aspx.cc/article/ey1xldyv-pidf-43lo-1wfl-fmy5ale1f635/read.aspx最后显示的结果有问题啊?
以txt读入的,显示出现以下问题:无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost/Stock/WebUI/ShowFile.aspx?ID=1' 时出错。 这是为什么?
string sql="SELECT * FROM TestFiles WHERE ID = '" + Request.QueryString["ID"] + "'";
SqlConnection connection = new SqlConnection("Server=.;uid=sa;pwd=;Database=TestUploadFile");
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read()){
Response.Clear();
Response.AddHeader("Content-Type",dr["FileType"].ToString());
Response.BinaryWrite((byte[])dr["MyFile"]);
}
dr.Close();
connection.Close();
}
当是txt格式时输出问题如下:无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost/Stock/WebUI/ShowFile.aspx?ID=1' 时出错。 这是为什么?
txt格式就可以显示出来,但有乱码
然后输出。编码问题就是这样引起的
1.responseEncoding="gb2312"可以解决txt乱码问题
但doc格式的又出现乱码?
2.如果保留Response.AddHeader("Content-Type",dr["FileType"].ToString());
则doc格式正常,但问题变为:
“无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
文本内容中发现无效字符。处理资源 'http://localhost/Stock/WebUI/ShowFile.aspx?ID=1' 时出错。 ”
3.即便解决了输出问题,但东西全济一块,没有原来的格式?
因为我主要是要处理一些案例,来源任意格式,但希望显示时能像文章那样,有格式和分段之类不是全堆一块