我正在尝试使用 HttpFileCollection 将视频文件上传到文件夹中,但它似乎没有保存在文件夹中。尽管路径正确,但它会给出一个错误,即找不到路径。这是我的代码
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" ImageUrl="~/ProductVideos/" runat="server" Width="118px" />
</div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
C#代码:
protected void Button1_Click(object sender, EventArgs e)
{
UploadVideoToFolder();
}
public string UploadVideoToFolder()
{
string vTitle = "";
string vDesc = "";
string FilePath = HttpContext.Current.Server.MapPath("~/ProductVideos/" + HttpContext.Current.Request.Form["title"]);
HttpFileCollection MyFileCollection = HttpContext.Current.Request.Files;
if (MyFileCollection.Count > 0)
{
// Save the File
try
{
MyFileCollection[0].SaveAs(FilePath);
return "1";
}
catch (Exception ex)
{
return "-1";
}
}
else
return "-1";
请帮我做这件事。