Advertisement
Advertisement
| 03.18.2008 at 07:35AM PDT, ID: 23250331 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 03.18.2008 at 08:13AM PDT, ID: 21151894 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: |
The upload aspx page
<%@ Page Language="c#" Src="UploadImage.aspx.cs" Inherits="DBImages.UploadImage"
MasterPageFile="~/YourAgent2.master" AutoEventWireup="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<h3>
Upload your Image</h3>
Enter A Friendly Name<input type="text" id="txtImgName" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
ControlToValidate="txtImgName"></asp:RequiredFieldValidator>
<br />
Select File To Upload:
<input id="UploadFile" type="file" runat="server" />
<asp:Button ID="UploadBtn" Text="Upload Me!" OnClick="UploadBtn_Click" runat="server">
</asp:Button>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<br />
</asp:Content>
Code behind
public void UploadBtn_Click(object sender, System.EventArgs e)
{
if (Page.IsValid) //save the image
{
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string img_contenttype = UploadFile.PostedFile.ContentType;
string img_name = txtImgName.Value;
byte[] img_data = new byte[imgLen];
int n = imgStream.Read(img_data, 0, imgLen);
String idis = Request.QueryString["id"];
int business_id = System.Convert.ToInt32(idis);
int RowsAffected = SaveToDB(img_name, img_data, img_contenttype, business_id);
if (RowsAffected > 0)
{
TextBox TextBox2 = new TextBox();
TextBox2.Text = "The Image was Saved";
/*Response.Write("<BR>The Image was saved");*/
}
else
{
Response.Write("<BR>An error occurred uploading the image");
}
}
}
private int SaveToDB(string img_name, byte[] img_data, string img_contenttype, int business_id)
{
//use the web.config to store the connection string
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["tempdbConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("INSERT INTO Image (img_name, img_data, img_contenttype, business_id) VALUES ( @img_name, @img_data,@img_contenttype,@business_id)", connection);
SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.VarChar, 50);
param0.Value = img_name;
command.Parameters.Add(param0);
SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);
param1.Value = img_data;
command.Parameters.Add(param1);
SqlParameter param2 = new SqlParameter("@img_contenttype", SqlDbType.VarChar, 50);
param2.Value = img_contenttype;
command.Parameters.Add(param2);
SqlParameter param3 = new SqlParameter("@business_id", SqlDbType.Int, 4);
param3.Value = business_id;
command.Parameters.Add(param3);
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
return numRowsAffected;
}
}
GetImage.aspx
<%@ Page Language="C#" MasterPageFile="~/YourAgent2.master" AutoEventWireup="true" CodeFile="GetImage.aspx.cs" Inherits="GetImage" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
CODE BEHIND
protected void Page_Load(object sender, EventArgs e)
{
System.Data.SqlClient.SqlDataReader Reader = null;
string ImageIdentity = Request.QueryString["id"].ToString();
SqlConnection sqlConnection = new SqlConnection(@"Data Source=ITDEV02\sqlexpress;Initial Catalog=tempdb;Integrated Security=True;");
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("Select img_data,img_contenttype from Image where business_id=" + ImageIdentity, sqlConnection);
Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
Reader.Read();
Response.Clear();
Response.ContentType = Reader["img_contenttype"].ToString();
/// Read the database image into a byte array
byte[] byteArray = (byte[])Reader["img_data"];
if (Request.QueryString["ThumbNail"] == null)
{
/// Move the byte array into a memory stream. This is an intermediate step to convert the byte array into
/// a system.Drawing.Image
System.IO.MemoryStream mstream = new System.IO.MemoryStream(byteArray, 0, byteArray.Length);
/// The System.Drawing image allows us to retrieve properties of the image (height width for example)
System.Drawing.Image dbImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(byteArray));
/// Create a new image - a thumbnail by changing the height and width
System.Drawing.Image thumbnailImage = dbImage.GetThumbnailImage(100, 100, null, new System.IntPtr());
/// Overwrite the memory stream with the Thumbnail Image getting the image format from the database image
thumbnailImage.Save(mstream, dbImage.RawFormat);
/// Convert the memory stream into a byte array
Byte[] thumbnailByteArray = new Byte[mstream.Length];
mstream.Position = 0;
mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length));
Response.BinaryWrite(thumbnailByteArray);
}
else
{
Response.BinaryWrite(byteArray);
}
// Response.BinaryWrite(thumbnailByteArray);
}
page called BUY.aspx to display in a datagrid
<%@ Page Language="C#" MasterPageFile="~/YourAgent2.master" AutoEventWireup="true"
CodeFile="Buy.aspx.cs" Inherits="Buy" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ImageIdentity" HeaderText="ImageIdentity" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn DataField="img_name" HeaderText="Image Name"></asp:BoundColumn>
<asp:BoundColumn DataField="img_contenttype" HeaderText="Image Type"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<a href='<%# "getImage.aspx?ThumbNail=\"N\"&ID=" + DataBinder.Eval(Container.DataItem,
"ImageIdentity") %>'>
<img runat="server" src='<%# "getImage.aspx?ID=" + DataBinder.Eval(Container.DataItem,
"ImageIdentity")%>' id="Img1" /></a>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</asp:Content>
CODE BEHIND
private void Page_Load(object sender, System.EventArgs e)
{
System.Data.SqlClient.SqlDataReader Reader = null;
SqlConnection SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["tempdbConnectionString"].ConnectionString);
SqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("GetImages", SqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataSource = Reader;
DataGrid1.DataBind();
}
|
| 03.18.2008 at 08:19AM PDT, ID: 21151981 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: |
In getImage.aspx
protected void Page_Load(object sender, EventArgs e)
{
System.Data.SqlClient.SqlDataReader Reader = null;
string ImageIdentity = Request.QueryString["id"].ToString();
SqlConnection sqlConnection = new SqlConnection(@"Data Source=ITDEV02\sqlexpress;Initial Catalog=tempdb;Integrated Security=True;");
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("Select img_data,img_contenttype from Image where business_id=" + ImageIdentity, sqlConnection);
Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
Reader.Read();
Response.Clear();
Response.ContentType = Reader["img_contenttype"].ToString();
/// Read the database image into a byte array
byte[] byteArray = (byte[])Reader["img_data"];
if (Request.QueryString["ThumbNail"] == null)
{
/// Move the byte array into a memory stream. This is an intermediate step to convert the byte array into
/// a system.Drawing.Image
System.IO.MemoryStream mstream = new System.IO.MemoryStream(byteArray, 0, byteArray.Length);
/// The System.Drawing image allows us to retrieve properties of the image (height width for example)
System.Drawing.Image dbImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(byteArray));
/// Create a new image - a thumbnail by changing the height and width
System.Drawing.Image thumbnailImage = dbImage.GetThumbnailImage(100, 100, null, new System.IntPtr());
/// Overwrite the memory stream with the Thumbnail Image getting the image format from the database image
thumbnailImage.Save(mstream, dbImage.RawFormat);
/// Convert the memory stream into a byte array
Byte[] thumbnailByteArray = new Byte[mstream.Length];
mstream.Position = 0;
mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length));
Response.BinaryWrite(thumbnailByteArray);
}
else
{
Response.BinaryWrite(byteArray);
}
// Response.BinaryWrite(thumbnailByteArray);
}
|
| 03.18.2008 at 09:51AM PDT, ID: 21153109 |