【问题标题】:File not found error while upload video files on youtube c#在 youtube c# 上上传视频文件时找不到文件错误
【发布时间】:2015-07-27 17:47:52
【问题描述】:

尝试了很多替代方案,但卡在filenotfound 错误。我需要文本框中的完整路径并在 Youtube 上上传视频。

public void UploadFileonYouTube()
{
    string filename = FileUpload1.FileName;
            string fullpath = Path.Combine(Directory.GetCurrentDirectory(), filename);
            YouTubeRequest request = new YouTubeRequest(settings);
            Video newVideo = new Video();
            newVideo.Title = "Demo";
            newVideo.Tags.Add(new MediaCategory("Animals", YouTubeNameTable.CategorySchema));
            newVideo.Description = "You tube Api Integration Demo.";
            newVideo.YouTubeEntry.Private = false;
            newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fullpath, "video/x-ms-wmv");
            request.Upload(newVideo);
    //@"C:\head_rush4.wmv"
}

设计:Fileupload 用于上传文件的控件。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button2" runat="server" Text="Upload on YouTube" OnClick="Button2_Click1"  />
    </div>
    </form>
</body>
</html>

【问题讨论】:

    标签: c# youtube-api


    【解决方案1】:

    在您的表单中使用enctype="multipart/form-data"

    string fullpath = FileUpload1.FileName;
    

    上面的代码只给你文件名,而不是文件路径。 MSDN Link

    【讨论】:

    • 在评论代码中查看我使用的 server.mappath 它也不能用于上传视频。
    • MapPath 方法将指定的相对或虚拟路径映射到服务器上对应的物理目录。它用于查找服务器上的路径,例如 Server.MapPath(~/uploads/videos/)
    猜你喜欢
    • 2023-03-12
    • 2021-01-05
    • 2012-08-04
    • 1970-01-01
    • 2017-01-11
    • 2019-02-20
    • 2013-07-02
    • 2012-03-26
    • 2011-11-21
    相关资源
    最近更新 更多