Click here to Skip to main content
15,916,042 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,I want to upload a perticular ext. file using asp upload button,is there any way either by javascript or c# code behind or anything else via which when user clicks on browse button,he/she should only see files of that perticular extension to upload.
Posted
Updated 26-Apr-11 0:26am
v2

You can try that in the Following way.

if (fileUploadCategoryImage.HasFile == true)
              {
                  categoryImageName = fn_UploadCategoryImage(fileUploadCategoryImage);
              }



public string fn_UploadCategoryImage(FileUpload UploadedFile)
    {
        HttpPostedFile file = UploadedFile.PostedFile;
        string fileExt = Path.GetExtension(file.FileName).ToLower();
        string fileName = Path.GetFileName(file.FileName);
        if (fileName != string.Empty)
        {
            try
            {
                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
                {

                    str = DateTime.Now.ToFileTime() + "_" + fileName;
                    file.SaveAs(Server.MapPath("~/admin/Upload/Category/") + str);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //str = fileName;
        return str;
    }
 
Share this answer
 
AFAIK I don't think asp:Fileupload can show only particular type of files in the dialog box.
But You can check for which type of files to upload.

see the discussion here How to make a file upload control to accept or upload only file extensions like .jpeg, .bmp, .pdf.[^]
 
Share this answer
 

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