如何上传pdf文件并检查其是否为pdf文件? [英] How to Upload pdf file and check if it s pdf file or not?

查看:92
本文介绍了如何上传pdf文件并检查其是否为pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何上传.pdf文件,然后检查其是否为.pdf文件?
我在asp.net中使用上载控件,但是在上载任何一个文件时发生错误.
所以我需要用C#上传代码.

谢谢Advance ..

How to Upload .pdf file and then check if it s .pdf file or not?
I am using Upload control in asp.net but while I upload any one file error occurred.
so I need Upload coding in C#.

Thanks Advance..

推荐答案

在上传前只需检查扩展名即可.

Just check extension before uploading.

if (FileUpload1.HasFile)
        {
            // Get the name of the file to upload.
            string fileName = Server.HtmlEncode(FileUpload1.FileName);
            // Get the extension of the uploaded file.
            string extension = System.IO.Path.GetExtension(fileName);
            // Allow only files with .doc or .xls extensions
            // to be uploaded.
            if (extension == ".pdf") 
{
//upload accordingly
}
            }


很难在不采取任何措施的情况下证明代码中的错误是正确的,但是您可以浏览
Its very hard to justify what is error in your code without taking its snap but you can navigate this[^] link to know how to upload file[.pdf] with checking it in ASP.net.


使用FileUpload控件& RegularExpressionValidator进行验证.

Use FileUpload control &RegularExpressionValidator to validate.

<asp:FileUpload ID="flUpld" runat="server" />

                <asp:RegularExpressionValidator

                    id="RegularExpressionValidator1" runat="server"

                    ErrorMessage="Only PDF files are allowed!"

                    ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\


这篇关于如何上传pdf文件并检查其是否为pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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