Click here to Skip to main content
11,805,604 members (53,607 online)
Rate this: bad
Please Sign up or sign in to vote.
Hi friends,

I am kind of a newbie in the ASP.NET. I need help as to what is the code for FileUpload that only accepts a pptx file, and when uploaded, the file will be displayed in the GridView.. Thanks so much!
Posted 13-Sep-12 21:48pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use fileuploader( to upload a file
below is the code to validate only .pptx file

if (FileUpload1.HasFile)
                string strFileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
                if (strFileExtension != null)
                    string validFileExtension = strFileExtension.ToLower();
                    if (validFileExtension == ".pptx")
                            string filepath = Server.MapPath("~/Images");
                            if (!Directory.Exists(filepath ))
                            string fileName = Guid.NewGuid().ToString().Replace("-", "") + strFileExtension; //to generate unique file name
                           FileUpload1.SaveAs(filepath  + "/" + fileName);
                        lblMessage.Text = "upload only pptx file";
Member 9324114 at 16-Sep-12 20:32pm
Hi, im sorry but I wanted to ask, why did you use the "UploadIcon" in the IF statement? By the way, here are the following information that I believe would contribute:

ID: FileUpload1
Database Data Type: varbinary(MAX)

The FileUpload will only accept pptx file, and when uploaded, it must appear in the GridView1.

Thank you Azziet, I appreciate your help :)
Thanks for the upcoming answers! Thanks alot!
Azziet at 26-Sep-12 1:32am
its just a fileuplaoder name (fileupload1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100