上载垂直扩展名的文件. [英] Uploading files of perticular extension.

查看:79
本文介绍了上载垂直扩展名的文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想上传一个垂直分机.使用asp上载按钮的文件,是否可以通过javascript或c#代码后面的任何方式,或通过其他任何方式在用户单击浏览按钮时通过他/她看到要上传的垂直扩展名的文件.

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.

推荐答案

您可以按照以下方式尝试.

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;
    }


AFAIK我认为asp:Fileupload不能在对话框中仅显示特定类型的文件.
但是您可以检查要上传的文件类型.

请参阅此处的讨论如何使文件上传控件仅接受或上传文件扩展名,例如.jpeg,.bmp,.pdf. [
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.[^]


这篇关于上载垂直扩展名的文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆