hi,
Can anyone help...
how to solve the problems when we upload files in server?
description:
i have one page(Associated college)..it has images...to show this i have to save this images in both folder and database...the problem is it is worked on the local...but when upload it on server it is not work out....how to solve?
code:
protected void btnnadd_Click(object sender, EventArgs e)
{
if (uploadcollogo.HasFile == true)
{
try
{
//string fileName = Server.HtmlEncode(uploadcollogo.FileName);
System.Drawing.Image image_file = System.Drawing.Image.FromStream(uploadcollogo.PostedFile.InputStream);
int image_height = image_file.Height;
int image_width = image_file.Width;
int max_height = 240;
int max_width = 320;
image_height = (image_height * max_width) / image_width;
image_width = max_width;
if (image_height > max_height)
{
image_width = (image_width * image_height) / image_width;
image_width = max_width;
}
Bitmap bitmap_file = new Bitmap(image_file, image_width, image_height);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bitmap_file.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
byte[] image = new byte[stream.Length + 1];
stream.Read(image, 0, image.Length);
string fileName = Path.GetFileName(uploadcollogo.FileName);
// string image1 = "../userside/collogo/" + fileName;
string status = "Active";
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
// SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["constring"].ToString());
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "pcolinsert";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@colname", txtcolname.Text);
cmd.Parameters.AddWithValue("@colmobile1", txtcolmobile1.Text);
cmd.Parameters.AddWithValue("@colmobile2", txtcolmobile2.Text);
cmd.Parameters.AddWithValue("@collandline", txtcollandline.Text);
cmd.Parameters.AddWithValue("@collemail1", txtcolemail.Text);
cmd.Parameters.AddWithValue("@colaltemail", txtcolaltemail.Text);
cmd.Parameters.AddWithValue("@coladdress", txtcoladdr.Text);
cmd.Parameters.AddWithValue("@colwebsite", txtcolwebsite.Text);
cmd.Parameters.AddWithValue("@colcountry", ddlcountry.SelectedItem.Text);
cmd.Parameters.AddWithValue("@colstate", ddlstate.SelectedItem.Text);
cmd.Parameters.AddWithValue("@colcity", txtcolcity.Text);
cmd.Parameters.AddWithValue("@collandmark", txtcollandmark.Text);
//cmd.Parameters.AddWithValue("@collogo", image);
cmd.Parameters.AddWithValue("@status", status);
SqlParameter UploadedImage = new SqlParameter("@collogo", SqlDbType.Image, image.Length);
UploadedImage.Value = image;
cmd.Parameters.Add(UploadedImage);
cmd.Connection = cn;
cmd.ExecuteNonQuery();
uploadcollogo.SaveAs(Server.MapPath("../userside/collogo/") + uploadcollogo.FileName);
// uploadcollogo.SaveAs(Server.MapPath(image1));
cn.Close();
clear();
Page.ClientScript.RegisterStartupScript(this.GetType(), "Inserted", "<script>alert('Record Inserted Sucessfuly')</script>");
}