2014-10-16 136 views
0

我想使用上传YouTube上的视频this code文件上传错误的文件路径

我已经

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(); 
    } 
} 

改变var filePath = @"REPLACE_ME.mp4";但我发现了一个错误,这是错的路径 enter image description here

我该如何解决这个问题? 另一个我曾尝试:

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

但同样的结果..

+0

如果您如果不提供完整路径,系统将使用当前运行在C:\ Program Files(x86)\ IIS Express上的应用程序的当前路径,这显然是IIS Express。解决方案:在保存之前提供完整路径。 – 2014-10-16 12:03:53

回答

2

您可能需要先保存文件中使用:

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

或者像你与FileStream类的工作,你总是可以尝试:

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

我认为你必须这样做:

Server.MapPath(FileUpload1.FileName); 

Controler.Server Property

编辑:

或只使用像这样的流如果你不一定要这样做localy AVE文件:

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

同样的结果。而我怎么知道Server.MapPath是用于服务器中的文件。我想通过客户端上传文件 – gsiradze 2014-10-16 11:58:20

+0

哦,我很抱歉。如果你只是想获得文件流,我会用这种方式使用FileUpload1.FileContent属性,你不必首先保存文件locale。 – t3chb0t 2014-10-16 12:06:30