0

この簡単なアップロードだけを試しました

デフォルト.aspx:

<AjaxControlToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" CompleteBackColor="White" 
OnUploadedComplete="AsyncFileUpload1_UploadedComplete" OnUploadedFileError="AsyncFileUpload1_UploadedFileError" 
OnClientUploadComplete="Success" OnClientUploadError="Error" /> 
    <br />
<asp:Button runat="server" ID="btnUpload" Text="Upload" Width="84px"/>
<asp:Label ID="Label1" runat="server"></asp:Label>

Default.aspx.cs:

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    //Fired on the server side when the file successfully uploaded 
    if (AsyncFileUpload1.HasFile)
    {
        AsyncFileUpload1.SaveAs(@"C:\Images\" + AsyncFileUpload1.FileName);
        Label1.Text = "Received " + AsyncFileUpload1.FileName + " Content Type " + AsyncFileUpload1.PostedFile.ContentType;
    }

}

protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    Label1.Text = "Error!!";
    //Fired on the server side when the loaded file is corrupted 

    //Display some error message here 
}
4

1 に答える 1

0

アノニクル、

この問題が解決しない場合は、以下のコードを試してください...

aspx:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
    <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" CompleteBackColor="White"
        OnUploadedComplete="AsyncFileUpload1_UploadedComplete" OnUploadedFileError="AsyncFileUpload1_UploadedFileError"
        OnClientUploadComplete="Success" OnClientUploadError="Error" />
</div>
<div>
    <asp:Button runat="server" ID="btnUpload" Text="Upload" Width="84px" OnClick="btnUpload_Click" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
</div>

<div>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div>
                <!--STYLE SELECTOR-->
                <div>
                    <h3>
                        VMB Explaining the stage
                    </h3>
                </div>
            </div>
            <!-- MEDIA PLAYER -->
            <sil:MediaPlayer ID="MediaPlayer1" runat="server" Width="600" Height="440" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>

また、アセンブリを登録します

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="sil" %> // Video Player

aspx.cs で

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    //Fired on the server side when the file successfully uploaded 
    if (AsyncFileUpload1.HasFile)
    {            
        _strFilePath = AppDomain.CurrentDomain.BaseDirectory + "Uploads\\" + AsyncFileUpload1.FileName;
        AsyncFileUpload1.SaveAs(_strFilePath);
        Label1.Text = "Received " + AsyncFileUpload1.FileName + " Content Type " + AsyncFileUpload1.PostedFile.ContentType;
        PlayUploadedFile();
    }

}

private void PlayUploadedFile()
{
    //Here is my Code

    #region Media Player initial settings
    MediaPlayer1.AutoPlay = true;
    MediaPlayer1.ScaleMode = System.Web.UI.SilverlightControls.ScaleMode.Zoom;
    MediaPlayer1.MediaSource = _strFilePath;
    MediaPlayer1.MediaSkinSource = "~/skin/Custom.xaml";
    #endregion

}

protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    Label1.Text = "Error!!";
    //Fired on the server side when the loaded file is corrupted 

    //Display some error message here 
}

ビデオプレーヤーの場合、最初にこれを調べる必要があります

SilverlightApplication.Web.dll および System.Web.Silverlight.dll を参照する必要があります。

それで全部です。

これがあなたの問題を完全に解決することを願っています:)

于 2012-05-25T11:53:44.740 に答える