{"id":59,"date":"2009-05-26T10:21:00","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.yazilimmutfagi.com\/?p=59"},"modified":"2009-05-26T10:21:00","modified_gmt":"1970-01-01T00:00:00","slug":"asp-net-ile-dosya-upload-islemi","status":"publish","type":"post","link":"https:\/\/www.yazilimmutfagi.com\/index.php\/2009\/05\/26\/asp-net-ile-dosya-upload-islemi\/","title":{"rendered":"Asp.Net ile Dosya Upload Islemi"},"content":{"rendered":"<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Selamlar bu dersimizde de asp.net kullanarak dosya upload etmeyi ve dosya upload ederken de bir takim kontrolleri kullanarak (regularexpression validator) upload islemini ger&ccedil;eklestirecegiz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">&Ouml;ncelikle .net 2.0 la birlikte hayatimiza girmis file upload nesnesini toolbox dan se&ccedil;ip &ccedil;alisma alanimiza atiyoruz ve bir de Upload butonu atiyoruz.Daha sonra ise bir adet regular expression validator atip controltovalidate &ouml;zelligine fileupload nesnemizi referans g&ouml;steriyoruz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">B&ouml;ylece file upload nesnemizi kontrol etmis olacagiz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\">&nbsp;<\/p>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\"><img decoding=\"async\" loading=\"lazy\" height=\"108\" width=\"534\" alt=\"\" src=\"http:\/\/www.yazilimmutfagi.com\/Makale\/Img\/MuratYilmaz\/Upload\/resim1.jpg\" \/><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Karsimiza buna benzer bir g&ouml;r&uuml;nt&uuml; &ccedil;ikiyor.Asp code behind tarafinda ise b&ouml;yle bir kod yaziyoruz.<br \/>\n<\/span><\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" style=\"background: rgb(238, 236, 225) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; border-collapse: collapse;\" class=\"MsoTableGrid\">\n    <tbody>\n        <tr style=\"\">\n            <td valign=\"top\" width=\"574\" style=\"border: 1pt solid black; padding: 0cm 5.4pt; width: 430.65pt; background-color: transparent;\">\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">File Name:<span style=\"color: blue;\">&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span> <span style=\"color: red;\">id<\/span><span style=\"color: blue;\">=&quot;filename&quot;<\/span> <span style=\"color: red;\">runat<\/span><span style=\"color: blue;\">=&quot;server&quot;&gt;&lt;\/<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span><span style=\"color: blue;\">&gt;&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">br<\/span> <span style=\"color: blue;\">\/&gt;<\/span><\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">File Content:<span style=\"color: blue;\">&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span> <span style=\"color: red;\">id<\/span><span style=\"color: blue;\">=&quot;filecontent&quot;<\/span> <span style=\"color: red;\">runat<\/span><span style=\"color: blue;\">=&quot;server&quot;&gt;&lt;\/<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span><span style=\"color: blue;\">&gt;&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">br<\/span> <span style=\"color: blue;\">\/&gt;<\/span><\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">File Size:<span style=\"color: blue;\">&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span> <span style=\"color: red;\">id<\/span><span style=\"color: blue;\">=&quot;filesize&quot;<\/span> <span style=\"color: red;\">runat<\/span><span style=\"color: blue;\">=&quot;server&quot;&gt;&lt;\/<\/span><span style=\"color: rgb(163, 21, 21);\">span<\/span><span style=\"color: blue;\">&gt;&lt;<\/span><span style=\"color: rgb(163, 21, 21);\">br<\/span> <span style=\"color: blue;\">\/&gt;<\/span><\/span><\/p>\n            <\/td>\n        <\/tr>\n    <\/tbody>\n<\/table>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: black; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Bu kodu yazmamizin esas amaci upload ettigimiz nesneyle ilgili adi, i&ccedil;erigi ve boyutuyla ilgili bilgileri html sayfa &ccedil;iktimizda g&ouml;r&uuml;nt&uuml;lemek istememiz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: black; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">C # kodu olarak da Upload Butonunun click metoduna;<\/span><\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" style=\"background: rgb(238, 236, 225) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; border-collapse: collapse;\" class=\"MsoTableGrid\">\n    <tbody>\n        <tr style=\"\">\n            <td valign=\"top\" width=\"574\" style=\"border: 1pt solid black; padding: 0cm 5.4pt; width: 430.65pt; background-color: transparent;\">\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">if<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> (dosyaUpload.HasFile)<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">{<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>dosyaUpload.SaveAs(<span style=\"color: rgb(163, 21, 21);\">@&quot;C:\\upload\\&quot;<\/span> + dosyaUpload.FileName);<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>span1.InnerHtml = <span style=\"color: rgb(163, 21, 21);\">&quot;Dosya upload edildi&quot;<\/span>;<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">}<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">filename.InnerHtml = dosyaUpload.PostedFile.FileName;<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">filecontent.InnerHtml = dosyaUpload.PostedFile.ContentType;<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">filesize.InnerHtml = dosyaUpload.PostedFile.ContentLength.ToString();<\/span><\/p>\n            <p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">uploaddetails.Visible = <span style=\"color: blue;\">true<\/span>;<\/span><\/p>\n            <\/td>\n        <\/tr>\n    <\/tbody>\n<\/table>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\"><br \/>\nb&ouml;yle bir kod yaziyoruz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Eger upload edilmis bir nesne varsa C:\/\/upload dizinine upload ger&ccedil;eklesmis olacak.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: black; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Burda dikkat etmemiz gereken bir noktada upload edilmek &uuml;zere sadece jpg,gif,bmp dosyalara izin verdik peki bu kontrol&uuml; nerde yaptik?Bu kontrol&uuml; de RegularExpressinValidator nesnemizin ValidationExpression metoduyla yaptik bu metoda referans olarak ^(([a-zA-Z]:)|(<\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\"><span style=\"\"><span class=\"MsoHyperlink\"><span style=\"text-decoration: underline;\"><span style=\"color: rgb(0, 0, 255);\">\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.jpg|.JPG|.gif|.GIF)$<\/span><\/span><\/span><\/span><span style=\"color: black;\"><span style=\"\">&nbsp; <\/span>b&ouml;yle bir expression yazdik.<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: black; line-height: 115%; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;\">Herkese iyi &ccedil;alismalar<\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>Selamlar bu dersimizde de asp.net kullanarak dosya upload etmeyi ve dosya upload ederken de bir takim kontrolleri kullanarak (regularexpression validator) upload islemini ger&#231;eklestirecegiz.<\/p>\n","protected":false},"author":522,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[407],"tags":[4266,5795,5621,5249,5012,6011,4510],"_links":{"self":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/users\/522"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":0,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}