Perşembe, Ocak 18, 2007

Upload Uygulaması

Formunuza 1 upload,button,label,textbox koyun ve codebehind ı aşağıdaki şekilde yazın.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("Yüklenen dosya ile ilgili bilgi" + ":

");
sb.Append("Adı : " + FileUpload1.PostedFile.FileName + "
");
sb.Append("Tipi : " + FileUpload1.PostedFile.ContentType + "
");
sb.Append("Boyutu : " + FileUpload1.PostedFile.ContentLength.ToString() + "
");
Response.Write(sb.ToString());
if (FileUpload1.PostedFile.ContentType == "application/octet-stream")
{
FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + "\\" + TextBox1.Text);
}
else
{
Response.Write("Belirtilen Dosya Tipi desteklenmiyor");
}
}
}

Böylece Sadece rar-zip uzantılı dosyalar upload edilebilecek

Hiç yorum yok: