Şub 28 2011

programcinin hali :=)

Category: by_derkan @ 14:58

Tags:

Şub 23 2011

Dosya Upload ve Boyutlandirma

Category: by_derkan @ 12:06

    public static bool DosyaUploadveBoyutlandirma(FileUpload FileUpload1, string yol, string isim,int genislik)
    {
        try
        {
            if (FileUpload1.FileName.Length > 0)
            {
                if (FileUpload1.HasFile)
                {
                    string uzanti = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                    if (uzanti == ".jpg" || uzanti == ".gif" || uzanti == ".jpeg" || uzanti == ".png" || uzanti == ".JPG" || uzanti == ".GIF" || uzanti == ".JPEG" || uzanti == ".PNG")
                    {
                        Bitmap src = Bitmap.FromStream(FileUpload1.PostedFile.InputStream) as Bitmap;


                        decimal origWidth = src.Width;                            // Orjinal Genişlik
                        decimal origHeight = src.Height;                          // Orjinal Yükseklik
                        decimal sngRatio = origWidth / origHeight;                        // Genişlik ve yükseklik oranı
                        int newWidth = genislik;                                            // İstenen genişlik
                        decimal newHeight_temp = newWidth / sngRatio;                     // Geçici yükseklik (genişlk/oran)
                        int newHeight = Convert.ToInt16(newHeight_temp);                  // Yeni genişlik(Geçici yüğksekliğin int hali)


                        if (src.Width <= genislik)
                        {
                            FileUpload1.SaveAs(@yol + "/" + isim + uzanti);
                        }
                        else
                        {
                            Bitmap result = ResizeBitmap(src, genislik, newHeight);
                            result.Save(@yol + "/" + isim + uzanti, ImageFormat.Jpeg);
                        }

                        return true;
                    }
                }
            }

            return false; ;
        }
        catch
        {
            // // dosya yüklenirken hata olşutu
            return false;
        }
    }

Tags:

Şub 23 2011

web.config den mail ayarlarını okuma

Category: c#by_derkan @ 11:11

    public static MailSettingsSectionGroup MailAyar()
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
        return(MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
    }

 

 

Response.Write("host: " + MailAyar().Smtp.Network.Host + "<br />");
Response.Write("port: " +
MailAyar().Smtp.Network.Port + "<br />");
Response.Write("Username: " +
MailAyar().Smtp.Network.UserName + "<br />");
Response.Write("Password: " +
MailAyar().Smtp.Network.Password + "<br />");
Response.Write("from: " +
MailAyar().Smtp.From + "<br />");

 

http://www.dotnetspider.com/forum/179482-how-get-mail-settings-from-web-config-file.aspx

Tags:

Ara 10 2010

MSSQL Trim

Category: SQLby_derkan @ 13:10

MsSql de boşluk almak için örnek kullanımı :)

 

UPDATE    Ilceler
SET              IlceAdi = LTRIM(RTRIM(IlceAdi))

Tags: ,

Ara 8 2010

Iframe 100% Yükseklik ve Genişlik

Category: Javascriptby_derkan @ 17:26
bir domain altında başka bir siteyi iframe ile göstermeye çalışırsanız iframe de width="100%" çalışır fakat height="100%"  çalışmaz.
varsayılan olarak iframe yüksekliği 250 px görünür.sitenin tamamını gösteremezsiniz.çözüm;


<
script type="text/javascript">
function resize_iframe()
{
var height=window.innerWidth;//Firefox

if (document.body.clientHeight)
{
height=document.body.clientHeight;//IE

}
document.getElementById("frame007").style.height = parseInt(height -

document.getElementById("frame007").offsetTop - 8) + "px";

}
window.onresize=resize_iframe;
</script>


KULLANIMI :)

<iframe id="frame007" width="100%" onload="resize_iframe()" src="http://www.siteniz.com/">
</iframe>

Tags: , ,

Ağu 25 2010

connectionStrings e Programatik key ekleme,düzenleme,silme

Category: c#by_derkan @ 22:38

 

       
using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration; // gerekmeyebilir

yoksa ekliyoruz.
 
 // connectionStrings e erişim

  public static string GetConnKey(string key) // varsa değer yoksa null döndürür
        {
            if (WebConfigurationManager.ConnectionStrings[key] != null)
            {
                return WebConfigurationManager.ConnectionStrings[key].ConnectionString;
            }
            else
            {
                return null;
            }
        }

// düzenleme
        public static bool SetConnValue(string anahtar, string deger) // bağlantı stringini set eder yoksa ekler :).anahtar boş olamaz!!!
        {
            try
            {
                Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
                ConnectionStringsSection connSettingsSection = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
 
                ConnectionStringSettings ss = new ConnectionStringSettings();
 
                ss.ConnectionString = deger;
                ss.Name = anahtar;
                ss.ProviderName = "System.Data.SqlClient";
 
                if (string.IsNullOrEmpty(GetConnKey(anahtar)))
                {
                    connSettingsSection.ConnectionStrings.Add(ss);
                    configuration.Save();
                }
                else
                {
                    connSettingsSection.ConnectionStrings[anahtar].ConnectionString = deger;
                    configuration.Save();
                }
 
                return true;
            }
            catch
            {
                return false;
            }
        }

// kaldırma


public static bool RemoveConnKey(string key) // conn keyi web.config den kaldırır
        {
            try
            {
                Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
                ConnectionStringsSection connSettingsSection = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
 
                if (GetConnKey(key) != null)
                {
                    connSettingsSection.ConnectionStrings.Remove(key);
                    configuration.Save();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }


Tags:

Ağu 25 2010

appSettings e Programatik key ekleme,düzenleme,silme

Category: c#by_derkan @ 22:24
yazdığım,derlediğim işe yarar statik method,fonksiyonları paylaşıyorum.bir yerden başlamak lazım.

using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration; // gerekmeyebilir

yoksa ekliyoruz.
 
 // appSettings e erişim


      public static string GetAppKey(string key) // varsa değeri yoksa null döndürür
        {
            return WebConfigurationManager.AppSettings[key];
        }

        public static int GetKeyInt(string key) // varsa değeri yoksa 0 döndürür
        {
            int result;
            Int32.TryParse(WebConfigurationManager.AppSettings[key], out result);
            return result;
        }

        public static bool GetKeyBool(string key) // True/False değer kontrolü yapar.
        {
            bool sonuc;
            bool.TryParse(GetAppKey(key),out sonuc);
            return sonuc;
        }

// düzenleme

        public static bool SetAppValue(string anahtar, string deger) // ayar varsa günceller yoksa ekler :=)
        {
            try
            {
                Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
                AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
 
                if (GetAppKey(anahtar) == null)
                {
                    appSettingsSection.Settings.Add(anahtar, deger);
                    configuration.Save();
 
                }
                else
                {
                    appSettingsSection.Settings[anahtar].Value = deger;
                    configuration.Save();
                }
 
                return true;
            }
            catch
            {
                return false;
            }
        }

// kaldırma

        public static bool RemoveAppKey(string key) // keyi web.config den kaldırır
        {
            try
            {
                Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
                AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
 
                if (GetAppKey(key) != null)
                {
                    appSettingsSection.Settings.Remove(key);
                    configuration.Save();
                }
 
                return true;
            }
            catch
            {
                return false;
            }
        }


Tags:

Tem 28 2010

windows 7 yapı 7600 bu windows kopyası orjinal değil sorunu çözümü

Category: Genelby_derkan @ 22:31

windows 7 yi w7lxe.exe ile aktif ettikten 3-4 ay sonra son güncellemelerle windows 7 yapı 7600 bu windows kopyası orjinal değil diye bir  yazı çıkmaya başlamıştı sağ alt köşede.

aşağıdaki crack yazıyı kaldırdı ve güncelleştirmeler de açık şu an... pek yararlı ilaç :=)

http://rapidshare.com/files/411685663/Sahte_Windows_Sorunu.rar

Tags: ,

Tem 9 2010

ListView OnItemDataBound FindControl ve DataBinder.Eval örnek kullanımı

Category: by_derkan @ 14:48

 

    <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" OnItemDataBound="ListView1_ItemDataBound"
DataSourceID="SqlDataSource1">   

    
    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            if (ListView1.EditItem == null) // edit te değiliz
            {
                ListViewDataItem item = e.Item as ListViewDataItem;
 
                int id = Convert.ToInt32(DataBinder.Eval(item.DataItem, "HaberId"));
                string tur = DataBinder.Eval(item.DataItem, "Tur").ToString();
                HyperLink HyperLink1 = (HyperLink)e.Item.FindControl("HyperLink1");
 
                switch (tur)
                {
                    case "Haber":
                        HyperLink1.NavigateUrl = "~/HaberDetay.aspx?HaberId=" + id;
                        break;
                    case "Yorum":
                        HyperLink1.NavigateUrl = "~/YaziDetay.aspx?YaziId=" + id;
                        break;
                    default:
                        break;
                }
            }
        }
    }

Tags: , , , ,

Tem 9 2010

UserControl e parametre aktarımı

Category: Asp.net | c#by_derkan @ 14:42

 

using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using by_derkan;
public partial class UserControl_Haber1 : System.Web.UI.UserControl
{
    private int _HaberId;
    public int HaberId
    {
        get
        {
            return _HaberId;
        }
        set
        {
            _HaberId = value;
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        //HaberId değişkeni değeriyle emrimize amade  :=)
// değere bağlı olarak yapılacak işlemler
    }
}


<%@ Register src="Haber1.ascx" tagname="Haber1" tagprefix="uc1" %>
<uc1:Haber1 ID="Haber1" HaberId='<%#Eval("Haber1") %>' runat="server" />

c# da herşeyin nesne olduğunu burada anladım.
class ta üye tanımla değer ver ona göre işlem yap :=)

Tags: ,