文件上传错误的文件路径

时间:2014-10-16 11:45:32

标签: c# asp.net .net file-upload

我正在尝试使用this code

在youtube上传视频

我已经通过

更改了var filePath = @"REPLACE_ME.mp4";
if (FileUpload1.HasFile)
{
    var filePath = FileUpload1.FileName; // Replace with path to actual movie file.

    using (var fileStream = new FileStream(filePath, FileMode.Open))
    {
        var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
        videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
        videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

        await videosInsertRequest.UploadAsync();
    }
}

但是我收到一条错误信息,说这是错误的路径 enter image description here

我该如何解决? 另一个我尝试过:

var filePath = FileUpload1.PostedFile.FileName;
var filePath = FileUpload1.PostedFile.ToString();
var filePath = Path.GetFileName(FileUpload1.FileName);

但结果相同..

2 个答案:

答案 0 :(得分:2)

您可能需要先使用以下方式保存文件:

var newFile = Server.MapPath(FileUpload1.FileName);
FileUpload1.SaveAs(newFile);

或者当你使用FileStream类时,你总是可以尝试:

FileUpload1.FileContent; // gets the file as a stream

答案 1 :(得分:1)

我认为你这样做了:

Server.MapPath(FileUpload1.FileName);

Controler.Server Property

编辑:

或者只是使用像这样的流,如果你不一定要保存文件localy:

youtubeService.Videos.Insert(video, "snippet,status", FileUpload1.FileContent, "video/*");