在上传teleerik中,连接被重置

本文关键字:连接 teleerik | 更新日期: 2023-09-27 18:12:11

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

The connection was reset.

telerik RadUpload的演示在这里

这是.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;
        }
    }
} 

谢谢! !

在上传teleerik中,连接被重置

我可以百分百肯定地告诉你这一行是:

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

可能是您没有连接服务器的权限,或者其他各种问题。

要测试这个,将"var targetFolder"更改为如下内容:

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

运行这个,它可以完美地工作,因此,你试图访问服务器上的路径是问题所在。

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

var targetFolder = @"''server'Users'"

这将访问那个服务器然后是我在我的域上的users文件夹