how to check validation in file uploading like .doc,.docx,.txt,.xls,.xlsx .with example in asp.net with c# language ,with code
how to check validation in file uploading like .doc,.docx,.txt,.xls,.xlsx .with example in asp.net with c# language ,with code?
Shivanand ArurPosted Oct 23, 2012, 2:01 PM
using System;
using System.IO;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
list.Add(".doc");
list.Add(".docx");
list.Add(".txt");
list.Add(".xls");
list.Add(".xlsx");
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
foreach (string s in list)
{
if (Extension == s)
{
Response.Write("File Type Not allowed. please choose some other file type");
// Or you can write your logic here
}
else
{
// Your Code Logic Comes here
}
}
}
}
You can write this code in the Button Click Event... Hope this helps you out..
Thank you!!!
Please mark this answer as accepted, if it helped!!!