代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
anf的二进制存入image类型,再序列化数据
作者:
/ 发布于
2011/1/5
/
843
<div>using System; using System.Web; using System.Collections;</div> <div>namespace test.binary { /**//// <summary> /// Class1 的摘要说明。 /// </summary> public class BlogSiteSettings { private Hashtable blogsettings = new Hashtable(); private int bloguserid = 0; private int blogpurview = 0; private string blogpassword = ""; public Hashtable BlogSettings { get { return blogsettings; } set { blogsettings = value; } } <div> public int BlogUserId { get { return bloguserid; } set { bloguserid = value; } } <div> public int BlogPurview { get { string key = "BlogPurview";</div> <div> if (blogsettings[key] != null) return (int) blogsettings[key]; else return blogpurview; } set { blogsettings["BlogPurview"] = value; } } public string BlogPassword { get { string key = "BlogPassword";</div> <div> if (blogsettings[key] != null) return (string) blogsettings[key]; else return blogpassword; } set { blogsettings["BlogPassword"] = value; } } } } <div><%@ Page language="c#" Codebehind="BlogSettings.aspx.cs" AutoEventWireup="false" Inherits="test.binary.BlogSettings" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>BlogSettings</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="<a href="http://schemas.microsoft.com/intellisense/ie5">http://schemas.microsoft.com/intellisense/ie5</a>"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:RadioButton id="rbpublic" style="Z-INDEX: 101; LEFT: 344px; POSITION: absolute; TOP: 88px" runat="server" Text="公开" GroupName="purview"></asp:RadioButton> <asp:RadioButton id="rbFriend" style="Z-INDEX: 102; LEFT: 440px; POSITION: absolute; TOP: 88px" runat="server" Text="对好友公开" GroupName="purview"></asp:RadioButton> <asp:RadioButton id="rbPrivate" style="Z-INDEX: 103; LEFT: 576px; POSITION: absolute; TOP: 88px" runat="server" Text="私人" GroupName="purview"></asp:RadioButton> <asp:TextBox id="txtPassword" style="Z-INDEX: 104; LEFT: 352px; POSITION: absolute; TOP: 120px" runat="server"></asp:TextBox> <asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server" Text="提交"></asp:Button> </form> </body> </HTML></div> <div>using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Configuration; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary;</div> <div>namespace test.binary { /**//// <summary> /// BlogSettings 的摘要说明。 /// </summary> public class BlogSettings : System.Web.UI.Page { protected System.Web.UI.WebControls.RadioButton rbpublic; protected System.Web.UI.WebControls.RadioButton rbFriend; protected System.Web.UI.WebControls.RadioButton rbPrivate; protected System.Web.UI.WebControls.TextBox txtPassword; protected System.Web.UI.WebControls.Button Button1; private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { BlogSiteSettings blogsiteSettings = GetBlogSettings(int.Parse(Request.QueryString["UserId"])); if(blogsiteSettings.BlogPurview == 0) this.rbpublic.Checked = true; else if(blogsiteSettings.BlogPurview == 1) this.rbFriend.Checked = true; else if(blogsiteSettings.BlogPurview == 2) this.rbPrivate.Checked = true; txtPassword.Text = blogsiteSettings.BlogPassword; } } <div> Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);</div> <div> } #endregion</div> <div> private void Button1_Click(object sender, System.EventArgs e) { int UserId = int.Parse(Request.QueryString["UserId"]); BlogSiteSettings blogsiteSettings = new BlogSiteSettings(); blogsiteSettings.BlogUserId = UserId; if(rbpublic.Checked) blogsiteSettings.BlogPurview = 0; else if(rbFriend.Checked) blogsiteSettings.BlogPurview = 1; else if(rbPrivate.Checked) blogsiteSettings.BlogPurview = 2; string k = txtPassword.Text.Trim(); blogsiteSettings.BlogPassword = txtPassword.Text.Trim(); SaveSiteSettings(blogsiteSettings); Response.Redirect("BlogSettings.aspx?UserId="+UserId); } public void SaveSiteSettings(BlogSiteSettings blogsiteSettings) { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); byte[] b; binaryFormatter.Serialize(ms, blogsiteSettings.BlogSettings); ms.Position = 0; b = new Byte[ms.Length]; ms.Read(b, 0, b.Length);</div> <div> SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"]); SqlCommand cmd = new SqlCommand("c_InsertBlogInfo",conn); cmd.CommandType = CommandType.StoredProcedure; conn.Open(); cmd.Parameters.Add("@i_UserId", SqlDbType.Int, 4).Value = blogsiteSettings.BlogUserId; cmd.Parameters.Add("@i_BlogSettings", SqlDbType.VarBinary, 7500).Value = b; cmd.ExecuteNonQuery(); cmd.Connection.Close(); cmd.Dispose(); conn.Close(); binaryFormatter = null; ms = null; } protected BlogSiteSettings GetBlogSettings(int UserId) { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"]); SqlCommand cmd = new SqlCommand("c_GetBlogInfo",conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@i_UserId",SqlDbType.Int,4).Value = UserId; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); BlogSiteSettings blogsiteSettings = new BlogSiteSettings(); while(dr.Read()) { try { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); Byte[] b;</div> <div> b = (byte[]) dr["BlogSettings"]; ms.Write(b, 0, b.Length); ms.Position = 0; blogsiteSettings.BlogSettings = (Hashtable) binaryFormatter.Deserialize(ms); blogsiteSettings.BlogUserId = (int) dr["UserId"]; } catch { conn.Close(); return blogsiteSettings; } } conn.Close(); return blogsiteSettings; } public static BlogSiteSettings PopulateSiteSettingsFromIDataReader(IDataReader dr) { BlogSiteSettings blogsiteSettings = new BlogSiteSettings(); BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); Byte[] b;</div> <div> b = (byte[]) dr["BlogSettings"]; ms.Write(b, 0, b.Length); ms.Position = 0; blogsiteSettings.BlogSettings = (Hashtable) binaryFormatter.Deserialize(ms); blogsiteSettings.BlogUserId = (int) dr["UserId"];</div> <div> return blogsiteSettings; } } } </div>
试试其它关键字
序列化
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3