28 Ağustos 2012 Salı

ASP.NET FileUpload işlemi


Mahmut Temur'un yazmış olduğu FileUpload  kodunun geliştirilmiş halidir. Kaynak: Mahmut Temur

Öncelikle bir proje oluşturalım veya var olan projemize eğer yok ise rezerve edilmiş bir klasör olan App_Code klasörünü ekleyelim.. Projenize normal bir klasör ekler gibi ekleyeceğiniz bu klasörü nasıl rezerveli hale getiririm diye bir soru geliyorsa aklınıza hiç telaş etmeyin siz normal bir şekilde App_Code isimli bir klasörü projenize eklediğinizde sistem otomatik olarak onu rezerve edilmiş hale getirecektir. Şimdi bu klasör içerisine bir adet "DosyaYukle.cs" isimli class dosyası ekleyelim.

Şimdi eklediğimiz DosyaYukle.cs isimli class dosyamızın kodlarını aşağıdaki gibi yazalım:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for DosyaYukle
/// </summary>
public class DosyaYukle
{
public DosyaYukle()
{

}

    public static string dosyaKaydet( FileUpload isim, string yol ,string fileGroup)
    {
        string filename = "";
        HttpPostedFile postedFile = isim.PostedFile;

        if (postedFile != null && postedFile.ContentLength > 0)
        {
            //
            string filePath = postedFile.FileName;
            FileInfo clientFileInfo = new FileInfo(filePath);
            string dosyaAdi = clientFileInfo.Name;
            //dosya adı
            filename = fileGroup + dosyaAdi.Remove(0, dosyaAdi.Length - 4);
            //ana dizinimiz
            string serverPath = HttpContext.Current.Server.MapPath(".");

            //yeni isim

            string newName = onEk() + dosyaAdi;

            //yeni yolumuz
            string yeniPath = serverPath + "/" + yol + "/" + newName;
            postedFile.SaveAs(yeniPath);

            filename = newName;
        }
        else
        {
            filename = "Null veya Dosya boyutu yetersiz";
        }
        return filename;
   
    }

    public static string onEk()
    {

        // kelimenin uzunluğu
        const int UZUNLUK = 3;

        // Güvenlik kelimesinde kullanılacak karakterler dizesidir.
        string[] m_Karakterler = new string[] {
                   "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" ,
                    "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" ,
                    "S" , "T" , "U" , "V" , "W" , "X" , "Y" , "Z" , "0" ,
                    "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9"
                };

        // Random olarak kelime oluşturabileceğimiz Random class'ının tanımlanmasıdır.
        Random m_Random = new Random();

        // Boş kelime
        string kelime = String.Empty;

        for (int i = 0; i < UZUNLUK; i++)
        {
            // Random oluşturulan rakamın index olarak kabul edilip, m_Karakterler dizesinden ilgili karakterin alındığı satırdır.
            kelime += m_Karakterler[m_Random.Next(m_Karakterler.Length - 1)];
        }


        return kelime;
       
    }
}

Gerekli FileUpload kontrolünü gerçekleştirdik. Şimdi ise projemize File Upload kontrolü ekleyelim ve gerekli kolaylıklar ile file upload işlemimizi gerçekleştirelim...

Şimdi projemizin FileUpload.aspx.cs kısmına geçelim ve gerekli fileupload işlemimizi adım adım gerçekleştirelim...

protected void Button1_Click(object sender, ImageClickEventArgs e)
    {
        string yuklenecek = FileUpload1.FileName;

        if (yuklenecek != "")
        {
            yuklenecek = DosyaYukle.dosyaKaydet(FileUpload1, "doc", yuklenecek);
        }

}

31 Temmuz 2012 Salı

REPLACE (Transact-SQL)




UPDATE urunler_db SET urun_adi = REPLACE(urun_adi, '0015', '0016');

Replace(sütun adı, eski veri, yeni veri)


REPLACE ( string_expression , string_pattern , string_replacement )

Msdn Page Link

28 Temmuz 2012 Cumartesi

Prettyphoto jquery lightbox



prettyPhoto is a jQuery lightbox clone. Not only does it support images, it also support for videos, flash, YouTube, iframes and ajax. It’s a full blown media lightbox. It is very easy to setup, yet very flexible if you want to customize it a bit. Plus the script is compatible in every major browser, even IE6. It also comes with useful APIs so prettyPhoto can be launched from nearly anywhere (yes, that includes Flash)!”

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/