无法升级asp.net中的pdf文件 [英] unable to uplaod pdf file in asp.net

查看:208
本文介绍了无法升级asp.net中的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fu2.aspx.cs" Inherits="fu2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

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

    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>
</body>
</html>






c#:
代码






c#:
code

using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class fu2 : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        string filePath = "~/fileup/";
        string fileName = FileUpload1.FileName.ToString();
        FileUpload1.SaveAs(Server.MapPath(filePath) + fileName);
    }
}



我要上传pdf时出现此错误
mscorlib.dll中发生了类型为"System.IO.DirectoryNotFoundException"的第一次机会异常


但是当我上传图像和txt文件等时,不会显示此错误.



i am getting this error when i want to upload pdf
A first chance exception of type ''System.IO.DirectoryNotFoundException'' occurred in mscorlib.dll


but this error is not display when i upload image and txt files etc

推荐答案

尝试略微更改保存方式:
Try changing the way you save it slightly:
FileUpload1.SaveAs(Server.MapPath(filePath) + fileName);

成为:

FileUpload1.SaveAs(Server.MapPath(filePath + fileName));

原因是MapPath不会在路径规范中添加尾随的``/''字符-因此您的文件会尝试保存到

The reason is that MapPath does not put a trailing ''/'' character on the path spec - so your file would be trying to save to

C:\mywebsite\fileupmypdffile.pdf


这篇关于无法升级asp.net中的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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