protected
void Button1_Click(object sender, EventArgs e)
{
if (this.FileUpload1.PostedFile.ContentLength > 2048000)
{
return;
}
string resimAdi = this.FileUpload1.PostedFile.FileName;
//resim'in adn almak i‡in..
resimAdi = resimAdi.Substring(resimAdi.LastIndexOf(
'\\') + 1);
//burada her klas”r i‡in ayr yol belirttim
string yol1 = Server.MapPath("~/images1/");
string yol2 = Server.MapPath("~/images2/");
string yol3 = Server.MapPath("~/images3/");
if (resimAdi == "") return;
Response.ContentType =
"image/gif";
string URI = FileUpload1.PostedFile.FileName;
//bitmap bizden String Url istiyor bizde
//FileUpload1'den gelen Yolu vercez..
System.Drawing.
Bitmap DestImage = new System.Drawing.Bitmap(URI);
//ilk 50x50 bir Kopyasn oluŸruralm oluŸturalm
System.Drawing.
Bitmap imgOutput1 = new System.Drawing.Bitmap(DestImage, 50, 50);
//200x200 resim kopyas
System.Drawing.
Bitmap imgOutput2 = new System.Drawing.Bitmap(DestImage, 200, 200);
//burayada 500x500 resim kopyas
System.Drawing.
Bitmap imgOutput3 = new System.Drawing.Bitmap(DestImage, 500, 500);
//50x50 resmi kaydetmek i‡in verdi§imiz yol
//yol1 bize images1 klasörünün altına Resmi adyla kaydetcek
imgOutput1.Save(yol1 + resimAdi, System.Drawing.Imaging.
ImageFormat.Jpeg);
//images2 ' altına 200x200 boyutta olan resm'i kaydetme
imgOutput2.Save(yol2 + resimAdi, System.Drawing.Imaging.
ImageFormat.Jpeg);
//images3 altna 500x500 resmi kaydetme
imgOutput3.Save(yol3 + resimAdi, System.Drawing.Imaging.
ImageFormat.Jpeg);
imgOutput1.Dispose();
imgOutput2.Dispose();
imgOutput3.Dispose();
//Burdan sonrası Resimlerin Yollarn tutmak i‡in veritabann'a insert Yapcaz.
SqlConnection conn = new SqlConnection("Data Source =halit-pc;Database = ResimTabani; Integrated Security = SSPI");
SqlCommand com = new SqlCommand("Insert Into Resimler (ResimAdi,ResimYolu1,ResimYolu2,ResimYolu3) values (@ResimAdi,@ResimYolu1,@ResimYolu2,@ResimYolu3)", conn);
com.Parameters.AddWithValue(
"@ResimAdi", resimAdi);
//50x50 boyutta olan resmin Yolu
com.Parameters.AddWithValue(
"@ResimYolu1", "~/images1/" + resimAdi);
//200x200 resmin Yolu
com.Parameters.AddWithValue(
"@ResimYolu2", "~/images2/" + resimAdi);
//500x500 resmin yolu
com.Parameters.AddWithValue(
"@ResimYolu3", "~/images3/" + resimAdi);
conn.Open();
int etkilenen = com.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
Not : Alıntı Değildir. .
(c) ReklamStore