文件上传错误的文件路径
问题描述:
我想使用上传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";
但我发现了一个错误,这是错的路径
我该如何解决这个问题? 另一个我曾尝试:
var filePath = FileUpload1.PostedFile.FileName;
var filePath = FileUpload1.PostedFile.ToString();
var filePath = Path.GetFileName(FileUpload1.FileName);
但同样的结果..
答
您可能需要先保存文件中使用:
var newFile = Server.MapPath(FileUpload1.FileName);
FileUpload1.SaveAs(newFile);
或者像你与FileStream类的工作,你总是可以尝试:
FileUpload1.FileContent; // gets the file as a stream
答
我认为你必须这样做:
Server.MapPath(FileUpload1.FileName);
编辑:
或只使用像这样的流如果你不一定要这样做localy AVE文件:
youtubeService.Videos.Insert(video, "snippet,status", FileUpload1.FileContent, "video/*");
如果您如果不提供完整路径,系统将使用当前运行在C:\ Program Files(x86)\ IIS Express上的应用程序的当前路径,这显然是IIS Express。解决方案:在保存之前提供完整路径。 – 2014-10-16 12:03:53