How to check validation in file uploading like .doc,.docx,.txt,.xls,.xlsx .with example in asp.net with c# language ,with code
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shivanand ArurRank #920 · 2.3K reputationPosted Oct 23, 2012, 10:01 AM EDT
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!!!