gsiradze
gsiradze

Reputation: 4733

File Upload wrong filepath

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 enter image description here

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

Answers (2)

t3chb0t
t3chb0t

Reputation: 18646

I think you have do this:

Server.MapPath(FileUpload1.FileName);

Controler.Server Property

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

Matt
Matt

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

Related Questions