Home / ASP.NET Wiki / .NET Framework Essentials / Send email with smtp authentication using ASP.NET 3.5 / how to send email with attachment from local machine / through fileupload control choose specific extension file

through fileupload control choose specific extension file

 Rate It (0)

if(IsPostBack)

{

Boolean fileOK=false;

String fileExtention=System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();   //check file extension

Response.Write(Extension is..."+fileExtension);

String[] allowedExtension={".gif",".png"}; //only two file extension are accepted

for(int i=0;i<allowedExtension.Length;i++)

{

if(fileExtention==allowedExtension[i])   //check both extension are same

{

fileOK=true;

}}}

if(fileOK)

{try{FileUpload.PostedFile.SaveAs(path+FileUpload1.FileName);

Label1.Text="FileUploaded!";

}

catch(Exception ex)

{

Label1.Text="File could not be uploaded";

}}

else

{

Label1.Text="cannot accept files of this type";

}

}

}

Revision number 1, Sunday, November 27, 2011 10:09:57 PM by tarunsaini

Comments

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. abiruban (1)