Click here to Skip to main content
15,791,739 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this my presentation view

<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="True" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="Head1" runat="server">

    <form id="form2" runat="server" method="post">
    <asp:Label ID="l1" Text="" runat="server"></asp:Label>
        <asp:Label ID="lbltitle" runat="server" Text="Title"></asp:Label><br />
        <asp:TextBox ID="txttitle" runat="server"></asp:TextBox><br/>
        <asp:Label ID="lbldescription" runat="server" Text="Description"></asp:Label><br/>
        <asp:TextBox ID="txtDescription" Rows="5" TextMode="MultiLine" Columns="5" runat="server"
            Height="46px" Width="125px"></asp:TextBox><br/>
         <asp:Label ID="lblCatogery" runat="server" Text="Catogery"></asp:Label><br/>
        <asp:DropDownList ID="ddlcatogery" runat="server" Height="16px" Width="123px">
 <asp:ListItem Value="Autos">Autos &amp; Vehicles</asp:ListItem>
            <asp:ListItem Value="Music">Music</asp:ListItem>
            <asp:ListItem Value="Animals">Pets &amp; Animals</asp:ListItem>
            <asp:ListItem Value="Sports">Sports</asp:ListItem>
            <asp:ListItem Value="Travel">Travel &amp; Events</asp:ListItem>
            <asp:ListItem Value="Games">Gadgets &amp; Games</asp:ListItem>
            <asp:ListItem Value="Comedy">Comedy</asp:ListItem>
            <asp:ListItem Value="People">People &amp; Blogs</asp:ListItem>
            <asp:ListItem Value="News">News &amp; Politics</asp:ListItem>
            <asp:ListItem Value="Entertainment">Entertainment</asp:ListItem>
            <asp:ListItem Value="Education">Education</asp:ListItem>
            <asp:ListItem Value="Howto">Howto &amp; Style</asp:ListItem>
            <asp:ListItem Value="Nonprofit">Nonprofit &amp; Activism</asp:ListItem>
            <asp:ListItem Value="Tech">Science &amp; Technology</asp:ListItem>
            </asp:DropDownList><br />

        <asp:Label ID="lblkeywords" runat="server" Text="Key words"></asp:Label><br/>
        <asp:TextBox ID="txtkeywords" runat="server"></asp:TextBox><br/><br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br /><br />
         <asp:Button ID="Button1" runat="server"  Text="Upload on youtube" onclick="Button1_Click" /> <br />






using System;
using System.Configuration;
using Google.YouTube;
using Google.GData.YouTube;
using Google.GData.Client;
using Google.GData.Extensions.MediaRss;
using System.Threading;

public partial class _Default : System.Web.UI.Page
private static readonly string YouTubeDeveloperKey = ConfigurationManager.AppSettings["YouTubeDeveloperKey"];

private static readonly string YouTubeCompany = ConfigurationManager.AppSettings["YouTubeCompany"];

private static readonly string YoutubeUserName = ConfigurationManager.AppSettings["YoutubeUserName"];

private static readonly string YoutubePassword = ConfigurationManager.AppSettings["YoutubePassword"];
string youtubeurl;
protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)
Session["title"] = txttitle.Text;
Session["description"] = txtDescription.Text;

string FileName = FileUpload1.FileName;
string fillPath = FileUpload1.PostedFile.FileName;
string content = FileUpload1.PostedFile.ContentType;
var newp = Server.MapPath("download/" + FileName);
FileUpload1.SaveAs(Server.MapPath("download/" + FileName));


var settings = new YouTubeRequestSettings("Ramdeo", YouTubeDeveloperKey, YoutubeUserName, YoutubePassword)
Timeout = int.MaxValue
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = txttitle.Text.Trim();
newVideo.Tags.Add(new MediaCategory(ddlcatogery.SelectedItem.Text, YouTubeNameTable.CategorySchema));
newVideo.Description = txtDescription.Text.Trim();
newVideo.Keywords = txtkeywords.Text.Trim();

newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(newp, content);

Video A = request.Upload(newVideo);

System.IO.File.Delete(Request.PhysicalApplicationPath + "download/" + FileName);
Session["youtubeurl"] = "" + A.VideoId + "&hl=en_US&fs=1&rel=0";

//Response.Redirect("viewVideo.aspx?Name=" + txttitle.Text+"descr="+txtDescription.Text+"url="+l1.Text);

catch(Exception ex)



Sometime this code works sometimes not.please help me i am tired now.i have been working on this problem since 10 days. me...
if it is possible then give the code to upload video using API 3.0 in ASP.NET
Debug and find out where is the exact issue.
ramdeo_angh 19-Jul-14 22:56pm    
i did it works .video is uploading.but some times it's throws exceptions
What is that exception and on which line it throws?
ramdeo_angh 20-Jul-14 12:46pm    
invalid credentials...
it's because of the region. i have upload it on server but our server works on shows me the suspicious login location because when we will upload the video my code will try to login with my username and password that i am operating from india but on live server it is try to login from us.that's why it is showing error....

i am frustrated now... please if you guys capable then please please write a proper code ....
please....i am here because it's the biggest community where we can ask and gain something..
Please see my answer.

1 solution

Read the following answers. You need to verify the login attempt.

1. .Net YouTube API Invalid Credentials[^]
2. YouTube OAuth: Why do some accounts give me “Invalid Credentials”?[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900