我用asp.net写上传的程序,上传图片、exe文件、zip文件都没有问题,但是一上传pdf文件到本地,程序就报错(找不到服务器或者白板),这是为什么呀?(数据库sqlserver2000,操作系统win2003)

解决方案 »

  1.   

    代码如下: <form id="Form1" method="post" runat="server" encType="multipart/form-data">
    <table cellSpacing="0" cellPadding="0" width="780" align="center">
    <tr>
    <td vAlign="top">
    <table width="780" bgColor="#ffffff">
    <tr>
    <td align="center">
    <table width="700">
    <tr align="center">
    <td class="titleSystem" height="40">添加电子报刊信息</td>
    </tr>
    </table>
    <table class="tableborder" borderColor="#f8bf26" cellSpacing="0" cellPadding="0" width="80%"
    border="1">
    <tr align="center" bgColor="#f8c967" height="30">
    <td colSpan="2"><font color="#ffffff">电子报刊基本信息</font></td>
    </tr>
    <tr height="30">
    <td align="right" width="25%" bgColor="#f9e5af">所属期号&nbsp;</td>
    <td width="75%" bgColor="#fefaef">&nbsp;第&nbsp;<asp:dropdownlist id="number" Runat="server" DataValueField="peri_number" DataTextField="peri_number"></asp:dropdownlist>&nbsp;期
    </td>
    </tr>
    <tr height="30">
    <td align="right" bgColor="#f9e5af">电子文档上传&nbsp;</td>
    <td bgColor="#fefaef">&nbsp;<input class="inputcss" id="pdf" type="file" size="40" name="pdf" runat="server">
    <asp:requiredfieldvalidator id="valPdf" Runat="server" ControlToValidate="pdf" ForeColor="saddlebrown" ErrorMessage="请上传电子文档"
    Display="Dynamic"></asp:requiredfieldvalidator></td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center"><asp:imagebutton id="submit" onmouseover="MM_swapImage('submit','','/Cms/Images/button_addElectronic_on.gif',1)"
    onmouseout="MM_swapImgRestore()" Runat="server" CausesValidation="True" ImageUrl="/Cms/Images/button_addElectronic.gif"></asp:imagebutton><asp:imagebutton id="cancel" onmouseover="MM_swapImage('cancel','','/Cms/Images/button_cancelElectronic_on.gif',1)"
    onmouseout="MM_swapImgRestore()" Runat="server" CausesValidation="False" ImageUrl="/Cms/Images/button_cancelElectronic.gif"></asp:imagebutton></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    private void submit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    if(Session["CmsAdmin"]!=null)
    {
    string pdfExt;
    string NewName = DateTime.Now.ToString("yyyyMMddHHmmss");
    int back = 0;
    try
    {
    if(Page.IsValid)
    {
    HttpPostedFile PostedPdf = pdf.PostedFile; pdfExt = System.IO.Path.GetExtension(PostedPdf.FileName).ToString().ToLower();
                                           
    //生成电子文档文件
    PostedPdf.SaveAs(pdfSavePath + NewName + pdfExt); ElectronicVO eVO = new ElectronicVO();
    eVO.Number = Convert.ToInt32(number.SelectedValue);
    eVO.Pdf = NewName + pdfExt; back = eP.AddElectronic(eVO);
    if(back>0) Page.Response.Write(PageView.NormalString("电子报刊添加成功!","Default.aspx"));
    else Page.Response.Write(PageView.ErrorString("电子报刊添加失败!数据库操作失败!"));
    }
    }
    catch(Exception ex)
    {
    Page.Response.Write(PageView.ErrorString("电子报刊添加错误:" + ex.Message));
    }
    }
    else
    {
    Page.Response.Redirect("/Cms/Login.aspx");
    }
    }