Reputation: 4733
I'm trying to upload video on youtube using this code
I have changed var filePath = @"REPLACE_ME.mp4";
by
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();
}
}
but I'm getting an error that it's wrong path
How can I solve that? Another I have tried:
var filePath = FileUpload1.PostedFile.FileName;
var filePath = FileUpload1.PostedFile.ToString();
var filePath = Path.GetFileName(FileUpload1.FileName);
but same result..
Upvotes: 0
Views: 1118
Reputation: 18646
I think you have do this:
Server.MapPath(FileUpload1.FileName);
EDIT:
or just use the stream like this if you do not necessarily have to save the file localy:
youtubeService.Videos.Insert(video, "snippet,status", FileUpload1.FileContent, "video/*");
Upvotes: 1
Reputation: 551
You may have to Save the file first using:
var newFile = Server.MapPath(FileUpload1.FileName);
FileUpload1.SaveAs(newFile);
Or as your working with the FileStream class you could always try:
FileUpload1.FileContent; // gets the file as a stream
Upvotes: 2