Sindbad~EG File Manager

Current Path : C:/Inetpub/vhosts/yuksekkariyer.com/httpdocs/admin/
Upload File :
Current File : C:/Inetpub/vhosts/yuksekkariyer.com/httpdocs/admin/VideoGaleri.aspx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using ImageResizer;

public partial class admin_Default2 : System.Web.UI.Page
{
    private string smallimageName;
    public static int silineceurunid;
    public static int altkatid, katid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.Cookies["UserID"] != null)
            {
                pnlYeniVideo.Visible = false;
                pnlVideoKayitUyari.Visible = false;
               altkatid = Convert.ToInt32(Request.QueryString["altkatid"].ToString());
               katid = Convert.ToInt32(Request.QueryString["katid"].ToString());
                using (OleDbConnection vt = new baglanti().baglan())
                {
                    vt.Open();
                    OleDbCommand cmd = new OleDbCommand("SELECT * FROM VideoGaleri ORDER BY Id DESC", vt);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    pagerReferans.DataSource = dt.DefaultView;
                    pagerReferans.BindToControl = rptUrunler;
                    rptUrunler.DataSource = pagerReferans.DataSourcePaged;
                    rptUrunler.DataBind();
                    vt.Close();
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
    }

    private string imageSave(FileUpload fileupload, string dosya, int genislik, int yukseklik)
    {
        if (fileupload.HasFile)
        {
            string extension = Path.GetExtension(fileupload.PostedFile.FileName).ToLower();
            //Resmin adını bir değişkene atatım
            string resimadi = "Resim" + DateTime.Now.ToString("MMddyyhhmmss") + ".jpg";

            //Resmimi kayıt edeceğim klasörümü seçtim.
            string uploadFolder = Server.MapPath("../upload/Temp/");

            //Resmimin boyutlandırmamış halini kayıt ettim.
            fileupload.SaveAs(uploadFolder + resimadi);

            //Daha sonra eklentimin metodlarını kullanarak resmimin boyutlandırma işlemini yaptım.
            ResizeSettings resizeCropSettings1 = new ResizeSettings("width=" + genislik + "&height=" + yukseklik + "&mode=pad");
            string fileName = Path.Combine(uploadFolder, resimadi);
            fileName = ImageBuilder.Current.Build(uploadFolder + resimadi, string.Concat(uploadFolder, Path.GetFileNameWithoutExtension(fileName)), resizeCropSettings1, false, true);//ŞU SATIRDAN SONRA İKİNCİ UZANTI EKLİYO yani jpg.jpg yapıyo bunu nasıl engellerim

            Bitmap imgOutput = new Bitmap(Server.MapPath("../upload/Temp/" + resimadi));// Büyük Boyutlu resmimizin Alındı Dosya Yeri  dosyanın önceki boyutu : 560 kb 
            Graphics outputGraphics = Graphics.FromImage(imgOutput);

            EncoderParameters myEncoderParameters = new EncoderParameters(3);
            myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 70L); // buradaki  45L yazan yer resmin kalitesine doğru orantılı olarak çalışıyor 100 yaparsanız en iyi şekilde resmi çıkarıyor ben boyuttan kısmak istediğim için 45 yaptım 
            myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
            myEncoderParameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);

            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType == "image/jpeg")
                    ici = codec;
            }
            imgOutput.Save(Server.MapPath("../upload/" + dosya + "/" + resimadi), ici, myEncoderParameters);//buraada ise resminizin nereye kaydedilmesini istiyorsanız onu seçiyorsunuz bu kod blogunu çalıştırdıktan sonra resimim kalitesi düşmüş olarak ( boyutu kb ) geri geldi ve sonraki halide 37 kb di 
            if (File.Exists(uploadFolder + resimadi))
            {
                outputGraphics.Dispose();
                imgOutput.Dispose();
                File.Delete(uploadFolder + resimadi);
            }
            smallimageName = resimadi;
        }
        return smallimageName;
    }

    //public string imageSave(string folder, int width, int height)
    //{
    //    if (fuKapakResmiDuyuru.HasFile)
    //    {
    //        string[] imageFormat = new[] { ".jpg", ".png", ".gif" };
    //        string extension = Path.GetExtension(fuKapakResmiDuyuru.PostedFile.FileName).ToLower();
    //        foreach (var s in imageFormat)
    //        {
    //            if (s == extension)
    //            {
    //                smallimageName = Genel.cleanText(txtVideoAciklama.Text.Replace("'","_")).ToLower() + "" +
    //                                  DateTime.Now.ToString("MMddyyhhmmss") + extension;
    //                string tempPath = Server.MapPath("../upload/_Temp/" + smallimageName);
    //                string imagesPath = Server.MapPath("../upload/" + folder + "/" + smallimageName);
    //                fuKapakResmiDuyuru.SaveAs(tempPath);

    //                int LargeSize = width; //resmin küçültüleceği boyut
    //                var image = new Bitmap(tempPath);

    //                using (Bitmap newImage = image)
    //                {
    //                    //double height = newImage.Height;
    //                    //double width = newImage.Width;
    //                    //double ratio = 0;

    //                    if (width >= LargeSize)
    //                    {
    //                        /* 700 boyutundaki resim oluşturma alanı başlangıç */
    //                        //ratio = width / height;
    //                        width = width;
    //                        height = height; // ratio;

    //                        var newValues = new Size(Convert.ToInt32(width), Convert.ToInt32(height));
    //                        var lastImage = new Bitmap(newImage, newValues);
    //                        lastImage.Save(imagesPath);
    //                        /* 700 boyutundaki resim oluşturma alanı bitiş */
    //                    }
    //                    else
    //                    {
    //                        if (!File.Exists(imagesPath))
    //                        {
    //                            fuKapakResmiDuyuru.SaveAs(imagesPath);
    //                            fuKapakResmiDuyuru.Dispose();
    //                        }
    //                    }

    //                    if (File.Exists(tempPath))
    //                    {
    //                        image.Dispose();
    //                        File.Delete(tempPath);
    //                    }
    //                }
    //            }
    //        }
    //    }
    //    return smallimageName;
    //}


    [WebMethod]
    public static bool Sil(int id)
    {

        string resimTemp;
        using (OleDbConnection vt = new baglanti().baglan())
        {
            vt.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM VideoGaleri WHERE Id=" + id, vt);
            OleDbDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            if (dt.Rows.Count > 0)
            {
                resimTemp = "../upload/Video/" + dt.Rows[0]["Kapak"].ToString();
                // string resimTempTemp = Server.MapPath(resimTemp);
                if (dt.Rows[0]["kapak"].ToString() != "noimage.jpg")
                {
                    if (File.Exists(HttpContext.Current.Server.MapPath(resimTemp)))
                    {
                        File.Delete(HttpContext.Current.Server.MapPath(resimTemp));
                    }
                }

            }
        }
        using (OleDbConnection vt = new baglanti().baglan())
        {
            vt.Open();
            OleDbCommand cmd = new OleDbCommand("DELETE FROM VideoGaleri WHERE Id=" + id, vt);
            cmd.ExecuteNonQuery();
            vt.Close();
        }
        return true;
    }

    protected void btnYeniUrunEkleme_OnServerClick(object sender, EventArgs e)
    {
        pnlYeniVideo.Visible = true;
    }

    protected void btnKaydet_OnServerClick(object sender, EventArgs e)
    {
        string code = txtVideoKodu.Text;
        if (!string.IsNullOrEmpty(txtVideoKodu.Text))
        {
            if (!string.IsNullOrEmpty(txtVideoAciklama.Text))
            {
                var newimage = imageSave(fuKapakResmiDuyuru,"video", 200, 200);
                if (newimage == null)
                {
                    newimage = "noimage.jpg";
                }
                using (OleDbConnection vt=new baglanti().baglan())
                {
                    vt.Open();
                    OleDbCommand cmd=new OleDbCommand("INSERT INTO VideoGaleri (VideoKod,Kapak,VideoAciklama,U) VALUES (@VideoKod,@Kapak,@VideoAciklama,U)",vt);
                    cmd.Parameters.AddWithValue("@VideoKod", txtVideoKodu.Text);
                    cmd.Parameters.AddWithValue("@Kapak", newimage);
                    cmd.Parameters.AddWithValue("@VideoAciklama", txtVideoAciklama.Text);
                    cmd.Parameters.AddWithValue("@U", 0);
                    cmd.ExecuteNonQuery();
                    vt.Close();
                    txtVideoAciklama.Text="";
                    txtVideoKodu.Text = "";
                    pnlVideoKayitUyari.Visible = false;
                    ltrVideoUyari.Text = "";
                    Response.Redirect("VideoGaleri.aspx?altkatid="+altkatid+"&katid="+katid+"");
                }
            }
            else
            {
                pnlVideoKayitUyari.Visible = true;
                ltrVideoUyari.Text = "Video Açıklaması Ekleyiniz.";   
            }
        }
        else
        {
            pnlVideoKayitUyari.Visible = true;
            ltrVideoUyari.Text = "Video Kodu Ekleyiniz.";
        }
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists