如何将.pdf上传到服务器? [英] How upload a .pdf to a server?

查看:525
本文介绍了如何将.pdf上传到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试上传pdf文件Windows Server 2012.



我已经给了文件夹完整的读,写,执行权限(我不确定是不是需要)。



代码适用于我的本地机器。当我将代码上传到服务器时,它会在web.config文件中显示自定义错误。



I am trying to upload a pdf file windows server 2012.

I have given the folder full read, write, execute privileges( I am not sure if that's needed).

The code works on my local machine. When I upload the code to the server its display the custom error on the web.config file.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>





我不确定是什么阻止了上传IIS或Web.config文件。< br $> b $ b

我尝试过:





I am not sure what is preventing the uploads IIS or the Web.config file.

What I have tried:

if (FileUpload1.HasFile)
            {
               int fileSize = FileUpload1.PostedFile.ContentLength;
               if (fileSize > 2097152)  
                {
                   Label1.Text = "The file size is to large please select a smaller size file";
                   Label1.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName);
                    if (fileExtension.ToLower() == ".pdf")
                    {
                        
                       FileUpload1.SaveAs(Server.MapPath("~/admin/uploads/" + FileUpload1.FileName.ToString() + ".pdf"));
                        Label1.Text = "File uploaded";
                        Label1.ForeColor = System.Drawing.Color.GreenYellow;
                    }
                    else
                    {
                        Label1.Text = "Please select the pdf file";
                    }
                }
            }
            else
            {
                Label1.Text = "Please select the file to upload";
                Label1.ForeColor = System.Drawing.Color.Red;
            }    

推荐答案

设置

< customErrors mode =On/>

并检查确切的错误。
set
<customErrors mode="On"/>
and check what is the exact error.


这篇关于如何将.pdf上传到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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