using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
public partial class filelimittype : System.Web.UI.Page
{
SqlConnection con=new SqlConnection("Data Source=AAPTI\\SQLEXPRESS;Initial Catalog=prashanth;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if(FileUpload1.HasFile)
{
if(FileUpload1.PostedFile.ContentLength<2100000)
{
string[] A=new string[]{".jpeg",".pdf",".txt",".doc"};
//FileUpload1.SaveAs(Server.MapPath("~/files"+extension));
string extension = Path.GetExtension(FileUpload1.FileName);
if (A.Contains(extension))
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string filepath = (Server.MapPath("~/images/" + filename));
FileUpload1.SaveAs(filepath);
SqlCommand cmd = new SqlCommand("insert into updwnload values('" + filename + "','"+filepath+"') ", con);
con.Open();
cmd.ExecuteNonQuery();
Response.Write("inserted");
Label1.Text = "filename:" + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + "<br>" + FileUpload1.PostedFile.ContentType;
}
else
{
Response.Write("selected file type is nt supported");
}
}
else
{
Response.Write("size is above 2mb");
}
}
else
{
Response.Write("invalid");
}
}
}
No comments:
Post a Comment