新浪微博头像上传功能有谁做过指点下 asp新浪微博头像上传功能有谁做过指点下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 头像上传可以采用二进制或者是存储文件的相对路径 我给你发一份二进制的你可以参考下写入数据库代码如下一个上传控件将上传控件名字name定义为up_file HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性 FileLength = UpFile.ContentLength; //记录文件长度 try { if (FileLength == 0) { //文件长度为零时 txtMessage.Text = "<b> 请你选择你要上传的图片</b>"; } else { Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组 Stream StreamObject = UpFile.InputStream; //建立数据流对像 //读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 StreamObject.Read(FileByteArray, 0, FileLength); //建立SQL Server链接 string stringcon = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString; SqlConnection Con = new SqlConnection(stringcon); String SqlCmd = "INSERT INTO indexsql(ImageData, ImageContentType, ImageSize)values(@Image, @ContentType, @ImageSize)"; SqlCommand CmdObj = new SqlCommand(SqlCmd, Con); Con.Open(); CmdObj.Parameters.Add("@Image", SqlDbType.Image); CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar, 50); CmdObj.Parameters.Add("@ImageSize", SqlDbType.Int); CmdObj.Parameters["@Image"].Value = FileByteArray; CmdObj.Parameters["@ContentType"].Value = UpFile.ContentType; CmdObj.Parameters["@ImageSize"].Value = UpFile.ContentLength; CmdObj.ExecuteNonQuery(); }读出代码如下,新建一个ASPX页面例如indexImage.aspxint ImgID = Convert.ToInt32(Request.QueryString["id"]); string stringcon = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString; SqlConnection Con = new SqlConnection(stringcon ); String SqlCmd = "select * from indexsql where id="+ImgID ; SqlCommand CmdObj = new SqlCommand(SqlCmd, Con); Con.Open(); SqlDataReader SqlReader = CmdObj.ExecuteReader(); SqlReader.Read(); Response.ContentType = (string)SqlReader["ImageContentType"]; Response.OutputStream.Write ((byte[])SqlReader["ImageData"], 0, (int)SqlReader["ImageSize"]); Response.End(); Con.Close();图片读取时可以用 <img src=indexImage.aspx align=left height =250 vspace="5" hspace="10" width="250" /> 或者用Image控件读取indexImage.aspx 看不懂呀!能不能发个dameo给我啊?[email protected] 谢谢O(∩_∩)O~ 图表控件类库源码 C#中用按钮实现翻页功能 我的mdi窗口BackgroundImage尺寸有问题 请教:服务器端没有公网IP,怎么做通过GPRS网络传输数据到服务器呢? 关于C#TabControl中动态添加控件的问题 取Session值滞后问题.... 一个dll中有2个类,2个类中有相同的public的变量名字可以吗? Linq查詢問題 在DataGrid怎样设置某列的宽度? 如何将如“#80ff80”的字符串转换成Color类型? WinForm 项目用了 EF做ORM模型,多线程处理数据的时候偶尔会出现 "未响应" 在win7下,怎么在登录前调用程序,并显示该程序的窗口?
写入数据库代码如下
一个上传控件将上传控件名字name定义为up_file
HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength; //记录文件长度
try
{
if (FileLength == 0)
{ //文件长度为零时
txtMessage.Text = "<b> 请你选择你要上传的图片</b>";
}
else
{
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray, 0, FileLength);
//建立SQL Server链接
string stringcon = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString;
SqlConnection Con = new SqlConnection(stringcon);
String SqlCmd = "INSERT INTO indexsql(ImageData, ImageContentType, ImageSize)values(@Image, @ContentType, @ImageSize)";
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
Con.Open();
CmdObj.Parameters.Add("@Image", SqlDbType.Image);
CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar, 50);
CmdObj.Parameters.Add("@ImageSize", SqlDbType.Int);
CmdObj.Parameters["@Image"].Value = FileByteArray;
CmdObj.Parameters["@ContentType"].Value = UpFile.ContentType;
CmdObj.Parameters["@ImageSize"].Value = UpFile.ContentLength;
CmdObj.ExecuteNonQuery();
}
读出代码如下,新建一个ASPX页面例如indexImage.aspx
int ImgID = Convert.ToInt32(Request.QueryString["id"]);
string stringcon = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString;
SqlConnection Con = new SqlConnection(stringcon );
String SqlCmd = "select * from indexsql where id="+ImgID ;
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
Con.Open();
SqlDataReader SqlReader = CmdObj.ExecuteReader();
SqlReader.Read();
Response.ContentType = (string)SqlReader["ImageContentType"];
Response.OutputStream.Write ((byte[])SqlReader["ImageData"], 0, (int)SqlReader["ImageSize"]);
Response.End();
Con.Close();
图片读取时可以用 <img src=indexImage.aspx align=left height =250 vspace="5" hspace="10" width="250" /> 或者用Image控件读取indexImage.aspx