Click here to Skip to main content
12,395,645 members (57,079 online)
Rate this:
 
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
 
good
Please Sign up or sign in to vote.

Solution 1

Use fileuploader(asp.net) 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 ))
                            {
                                Directory.CreateDirectory(imagePath);
                            }
                            string fileName = Guid.NewGuid().ToString().Replace("-", "") + strFileExtension; //to generate unique file name
                           FileUpload1.SaveAs(filepath  + "/" + fileName);
 
                    }
                    else
                    {
                        lblMessage.Text = "upload only pptx file";
                        return;
                    }
              }
    }
  Permalink  
v3
Comments
Member 9324114 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2016
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