2012-05-23 40 views
0

上傳後自動播放視頻,我只試過這種簡單的上傳如何使用ASPX C#

的Default.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 
} 
+0

你有任何soln: - | –

回答

0

anonyckles,

如果您仍有此問題,請在下面嘗試下面的代碼...

在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 
} 

For Video Player you have to look into this initially

需要引用SilverlightApplication.Web.dll和System.Web.Silverlight.dll

就是這樣。

希望這將完全解決您的問題:)

+0

我在哪裏可以找到SilverlightApplication.Web.dll文件? – anonyckles

+0

@anonyckles從我之前發佈的鏈接中下載樣本並查看bin文件夾...還定期檢查您的問題狀態... –