在上传Telerik中重置了连接

时间:2011-10-21 07:57:32

标签: c# asp.net upload telerik

我编写了类似telerik上传示例的示例,但在提交时出现以下错误(在FF中):

The connection was reset.

telerik RadUpload的演示是here

这是.aspx文件的代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage1.master" AutoEventWireup="true" CodeFile="Upload.aspx.cs" Inherits="Main_Upload" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<title>Upload file</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<telerik:RadScriptManager ID="rsmScriptManager" runat="server">
</telerik:RadScriptManager>
<telerik:RadProgressManager ID="rpmUploadFile" runat="server" />
<div style=" color:Green">Valid files(*.doc, *.docx, *.xls, *.xlsx, *.pdf)</div>
<telerik:RadUpload ID="rulFiles" runat="server" InitialFileInputsCount="2" MaxFileInputsCount="5" AllowedFileExtensions=".doc,.docx,.xls,.xlsx,.pdf">
</telerik:RadUpload>
<telerik:RadProgressArea runat="server" ID="rpaUpload"></telerik:RadProgressArea>
<asp:Button ID="btnUpload" runat="server" Text="Ok" OnClick="btnUpload_Click" />
<br />
<asp:Label ID="lblNoResults" runat="server" Visible="True">No uploaded file!</asp:Label>
<asp:Repeater ID="rptValidResults" runat="server" Visible="false">
    <ItemTemplate>
        <%#DataBinder.Eval(Container.DataItem,"FileName") %>(<%#DataBinder.Eval(Container.DataItem,"ContentLength").ToString() + " bytes" %>)<br />
    </ItemTemplate>
</asp:Repeater>

<div style="color: red; padding-top: 40px;">Invalid files:</div>
<asp:Label id="lblNoInvalidResults" runat="server" Visible="True">No invalid files.</asp:Label>
<asp:Repeater ID="rptInvalidResults" runat="server" Visible="false">
    <ItemTemplate>
        File: <%#DataBinder.Eval(Container.DataItem,"FileName") %>(<%#DataBinder.Eval(Container.DataItem,"ContentLength").ToString() + " bytes" %>)<br />
        Mime-type: <%#DataBinder.Eval(Container.DataItem,"ContentType") %>
    </ItemTemplate>
</asp:Repeater>

* .cs文件中的代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Main_Upload : System.Web.UI.Page
{
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        BindValidResult();
        BindInvalidResult();
    }

    private void BindValidResult()
    {
        if(rulFiles.UploadedFiles.Count > 0)
        {
            foreach (UploadedFile validFile in rulFiles.UploadedFiles)
            {
                var targetFolder = Server.MapPath(Commons.PAGER.UPLOAD_FOLDER);
                validFile.SaveAs(Path.Combine(targetFolder,validFile.GetName()),true);
            }

            lblNoResults.Visible = false;
            rptValidResults.Visible = true;
            rptValidResults.DataSource = rulFiles.UploadedFiles;
            rptValidResults.DataBind(); 
        }
        else
            {
            lblNoResults.Visible = true;
            rptValidResults.Visible = false;
        }
    }

    private void BindInvalidResult()
    {
        if(rulFiles.InvalidFiles.Count > 0)
        {
            lblNoInvalidResults.Visible = false;
            rptInvalidResults.Visible = true;
            rptInvalidResults.DataSource = rulFiles.InvalidFiles;
            rptInvalidResults.DataBind();
        }
        else
        {
            lblNoInvalidResults.Visible = true;
            rptInvalidResults.Visible = false;
        }
    }
} 

感谢!!!!

1 个答案:

答案 0 :(得分:0)

我会继续告诉你几乎100%确定造成这种情况的一行是:

var targetFolder = Server.MapPath(Commons.PAGER.UPLOAD_FOLDER);

可能是您无权连接服务器或其他各种问题。

要将此更改“var targetFolder”测试为:

var targetFolder = @"C:\Users\j\Desktop\TEMP\"

运行它并且它完美运行,因此您尝试在服务器上访问的路径是一个问题。

如果可能的话,也许你应该指定路径。例如,如果您在域中:

var targetFolder = @"\\server\Users\"

这将访问该服务器,然后访问我域中的用户文件夹。