我只尝试过这个简单的上传
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 :(得分: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
就是这样。
希望这将彻底解决您的问题:)