Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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

C#
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;
                    }
              }
    }
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900