rt
解决方案 »
- 正则问题,求解释。
- ASP.NET 一个内容页显示不同内容
- 请教:Hashtable组成新数据排序问题
- 下载下来的2.0系统aspx文件下面没有相应的aspx.cs文件怎么回事?
- 请教Ajax的一个问题
- 搞了一天没搞懂,在线急等啊
- asp.net 在制作页面方面的解决方案
- treeview中AutoPostBack设置为True的话,刷新闪烁得厉害,有没有好的解决方法呢?
- 请问为什么我的网页上的链接是红色的,但是将它包涵在TOP.ASXC里就变成蓝色了?
- 如何在*.cs文件中调用web.config内的key值。
- 连接数据库的问题 100分提供
- 请教:多语言乱码问题,100分求教,在线等!!!!
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
namespace DoitCNOA.Gwmod.Gwnz
{
/// <summary>
/// Binary 的摘要说明。
/// </summary>
public class Binary
{
protected System.Data.SqlClient.SqlConnection conn;
/// <summary>
/// get byte[] of file
/// </summary>
/// <param name="filepath">docupath</param>
/// <returns>return byte[] of docu</returns>
public byte[] GetDocu(string filepath)
{
System.IO.FileStream fs=new FileStream(filepath,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] docu=new byte[Convert.ToInt32(fs.Length)];
fs.Read(docu,0,Convert.ToInt32(fs.Length));
fs.Close();
return docu;
}
/// <summary>
/// 存储模板操作;
/// </summary>
/// <param name="filepath">dotpath</param>
/// <param name="dotname">dotname</param>
/// <param name="tempid">update the rowid(default:0--insert;**--update)</param>
/// <param name="sign">区别存储过程的标志</param>
public void operdot(string filepath,string dotname,int tempid,int sign)
{
conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
conn.Open();
SqlCommand comms=new SqlCommand();
comms.Connection=conn;
comms.CommandType=System.Data.CommandType.StoredProcedure;
byte[] dots=GetDocu(filepath);
if(sign==1)
{
if(tempid==0)
{
comms.CommandText="insertblob";
comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
comms.Parameters["@sign"].Value=sign;
comms.Parameters["@typename"].Value=dotname;
comms.Parameters["@dotblob"].Value=dots;
}
else
{
comms.CommandText="updateblob";
comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
comms.Parameters.Add("@id",System.Data.SqlDbType.Int,4);
comms.Parameters["@sign"].Value=sign;
comms.Parameters["@typename"].Value=dotname;
comms.Parameters["@dotblob"].Value=dots;
comms.Parameters["@id"].Value=tempid;
}
}
if(sign==2)
{
//update
comms.CommandText="updateblob";
comms.Parameters.Add("@sign",System.Data.SqlDbType.Int,4);
comms.Parameters.Add("@typename",System.Data.SqlDbType.VarChar,50);
comms.Parameters.Add("@dotblob",System.Data.SqlDbType.Image,dots.Length);
comms.Parameters.Add("@id",System.Data.SqlDbType.Int,4);
comms.Parameters["@sign"].Value=sign;
comms.Parameters["@typename"].Value=dotname;
comms.Parameters["@dotblob"].Value=dots;
comms.Parameters["@id"].Value=tempid; }
comms.ExecuteNonQuery();
System.Web.HttpContext.Current.Response.Write("<script>alert('保存成功!');</script>");
comms.Dispose();
conn.Close();
conn.Dispose();
conn=null;
}
/// <summary>
/// look templete of dot
/// </summary>
/// <param name="sql">select sql</param>
/// <param name="colname">字段名称</param>
public void getdot(string sql,string type,string colname,string filename)
{
try
{
conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
conn.Open();
SqlCommand comm=new SqlCommand(sql,conn);
SqlDataReader r=comm.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
if(r.Read())
{
//type=".dot";
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition","filename="+System.Web.HttpContext.Current.Server.UrlEncode(r[""+filename].ToString())+type);
System.Web.HttpContext.Current.Response.ContentType="application/msword";
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);
}
System.Web.HttpContext.Current.Response.Flush();
//System.Web.HttpContext.Current.Response.End();
r.Close();
comm.Dispose();
conn.Close();
conn.Dispose();
conn=null;
}
catch(System.Exception error)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('文档无内容!');</script>");
return;
}
}
/// <summary>
/// delete templete
/// </summary>
/// <param name="dotid">rowid</param>
public void deldot(string dotid)
{
conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString());
conn.Open();
SqlCommand comm=new SqlCommand("delete from dottype where id="+dotid,conn);
comm.ExecuteNonQuery();
System.Web.HttpContext.Current.Response.Write("<script>alert('删除成功!');</script>");
comm.Dispose();
conn.Close();
conn.Dispose();
conn=null;
}
}
}
System.Web.HttpContext.Current.Response.ContentType="application/msword";
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);因为我是 word,所以你只要改成你的类型就可以了
http://community.csdn.net/Expert/topic/5086/5086941.xml?temp=.3099634
这是我昨天发的帖子,谁如果能解决我连这个的分一起给
http://community.csdn.net/Expert/topic/5080/5080362.xml?temp=.7326929
这个是我第一次发的。
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])r[""+colname]);
ie会自动调用word,然后就跑到wrod编辑环境里面去了。我的意思就是要有一个像richtextbox这样的控件在ie的一个部分区域内显示出来。
http://www.2mysite.net/blogview.asp?logID=134
比如你在页面中加一个表格
<table>
<tr>
<td>
<iframe name="iframe" src="./a.aspx" frameborder="0"></iframe>
</td>
</tr>
</table>
System.Web.HttpContext.Current.Response.ContentType="application/msword";
这个是显示word的,你的不是word,所以要改一下类型,
你说的方法我试验了一下,用iframe可以显示出来,不过这个显示的实际是调用了word,我的意思是就像看一个图片一样,没有word的边框和菜单,比如象richtextbox那样,而且我从数据库中调用出来的就是一个word文档,我的想法是像一个Label控件一样,用户只能看,不能改。
我看了一下,由于对rtf的编码规则不是很懂,所以有些地方还是不太清楚。我昨天看msdn中好像有写rtf编码规则的,里面好像就有图片的保存位置。然后我试着在freetextbox中把rtf粘贴过去,通过freetextbox的html转换看到图片的转换位子了。其实我现在想法很简单,只要能够实现向ftb那样显示图片+文字就可以了,实在不行就改造ftb。