|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[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! |
||
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: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: |
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OmegaLove.BLL;
using System.Drawing;
using Telerik.Web.UI;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
namespace OmegaLove.Web.UI
{
public partial class ctrlUserProfilePics : OmegaLoveBasePageUserControl
{
private string strUsrId;
private void Page_Load(object sender, EventArgs e)
{
System.Web.Security.MembershipUser mu = System.Web.Security.Membership.GetUser();
strUsrId = mu.ProviderUserKey.ToString();
//if (!Page.IsPostBack)
//{
// GridView1.DataSource = FetchAllImagesInfo().Tables[0];
// GridView1.DataBind();
//}
}
public string GetConnectionString()
{
//sets the connection string from your web config file "ConnString" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["dbaspnetConnectionString"].ConnectionString;
}
private void ExecuteInsert(byte[] Image, string Type, Int64 Size, string Name, int length)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO tbl_Images (img_title, img_stream, img_type, img_size, img_is_primary, UserId) VALUES "
+ " (@img_title, @img_stream, @img_type, @img_size, 0, @UserId)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[5]; // 5 parameters
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new SqlParameter("@img_title", SqlDbType.NVarChar, 50);
param[1] = new SqlParameter("@img_stream", SqlDbType.Image, length);
param[2] = new SqlParameter("@img_type", SqlDbType.NVarChar, 50);
param[3] = new SqlParameter("@img_size", SqlDbType.BigInt, 9999);
param[4] = new SqlParameter("@UserId", SqlDbType.VarChar, 50);
param[0].Value = Name;
param[1].Value = Image;
param[2].Value = Type;
param[3].Value = Size;
param[4].Value = strUsrId;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void UploadButton_Click(object sender, EventArgs e)
{
//get the image file that was posted (binary format)
if (FileUpload1.PostedFile == null || FileUpload1.PostedFile.FileName == "")
{
lblResult.Text = "Please Select the file";
}
else
{
byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
try
{
if (Image.ContentLength > 0)
{
Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
int length = theImage.Length; //get the length of the image
string fileName = FileUpload1.FileName.ToString(); //get the file name of the posted image
string type = FileUpload1.PostedFile.ContentType; //get the type of the posted image
int size = FileUpload1.PostedFile.ContentLength; //get the size in bytes that
//Call the method to execute Insertion of data to the Database
ExecuteInsert(theImage, type, size, fileName, length);
lblResult.Text = "";
lblResult.Text = "<br>";
lblResult.Text += "File Content Type: " +
Image.ContentType + "<br>";
lblResult.Text += "File Size: " +
Image.ContentLength + "kb<br>";
lblResult.Text += "File Name: " +
Image.FileName + "<br>";
lblResult.Text += "Saved Successfully!";
GridView1.DataBind();
}
}
catch (Exception Ex)
{
lblResult.Text += "Error: <br>" + Ex.Message;
}
}
}
private DataSet FetchAllImagesInfo()
{
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dbaspnetConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(strConnString);
DataSet myDataSet = new DataSet();
try
{
conn.Open(); //open the connection
SqlCommand myCommand = new SqlCommand("select * from tbl_images where UserId=@UserId", conn);
myCommand.CommandType = CommandType.Text;
// Add Parameters to Command
SqlParameter UserId = new SqlParameter("@UserId", SqlDbType.VarChar, 50);
UserId.Value = strUsrId;
myCommand.Parameters.Add(UserId);
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
myAdapter.Fill(myDataSet);
conn.Close();
}
catch (SqlException SQLexc)
{
Response.Write("Data Retrival Failure. Error Details : " + SQLexc.ToString());
}
return myDataSet;
}
// private void ViewStatusMsg(string msg, string type)
// {
//ctrlGPStatusBox.message = msg;
//ctrlGPStatusBox.visible = true;
//ctrlGPStatusBox.type = type;
//ctrlGPStatusBox.setVisible(true);
// }
//private DataSet FetchAllImagesInfo()
//{
// String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dbaspnetConnectionString"].ConnectionString;
// SqlConnection conn = new SqlConnection(strConnString);
// try
// {
// conn.Open(); //open the connection
// SqlCommand myCommand = new SqlCommand("select * from tbl_images where UserId=@UserId", conn);
// myCommand.CommandType = CommandType.Text;
// // Add Parameters to Command
// SqlParameter UserId = new SqlParameter("@UserId", SqlDbType.VarChar, 50);
// UserId.Value = strUsrId;
// myCommand.Parameters.Add(UserId);
// SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
// DataSet myDataSet = new DataSet();
// myAdapter.Fill(myDataSet);
// conn.Close();
// return myDataSet;
// }
// catch (SqlException SQLexc)
// {
// Response.Write("Data Retrival Failure. Error Details : " + SQLexc.ToString());
// }
// return null;
//}
//private DataTable GetData(SqlCommand cmd)
//{
// DataTable dt = new DataTable();
// String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dbaspnetConnectionString"].ConnectionString;
// SqlConnection con = new SqlConnection(strConnString);
// SqlDataAdapter sda = new SqlDataAdapter();
// cmd.CommandType = CommandType.Text;
// cmd.Connection = con;
// try
// {
// con.Open();
// sda.SelectCommand = cmd;
// sda.Fill(dt);
// return dt;
// }
// catch
// {
// return null;
// }
// finally
// {
// con.Close();
// sda.Dispose();
// con.Dispose();
// }
//}
}
}
|
Advertisement
| Hall of Fame |