Uploading a video file or Youtube url, If iuploading video its working fine but when insert you-tube URL then it cant be save in db..
Unable to pick here txtYoutubeUrl..and save the url in data base.i want to save local uploaded video path or urlvideo path in same column..
plz give me some solution for this....
Thanks..
What I have tried:
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if(uploadVideo.HasFile)
{
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.ToString("MMMM");
//string Time = DateTime.Now.Hour.ToString();
string dirUrl = Path.Combine("../nvaVideoGallery" + Page.User.Identity.Name, Year, Month);
string DirPath = Server.MapPath(dirUrl);
if (!Directory.Exists(DirPath))
{
Directory.CreateDirectory(DirPath);
}
string fileUrl = string.Empty;
if(uploadVideo.HasFile)
{
string strFileNameWithoutExtension = Path.GetFileNameWithoutExtension(uploadVideo.PostedFile.FileName);
string strFileExtension = Path.GetExtension(uploadVideo.PostedFile.FileName);
string uniqueFileName = strFileNameWithoutExtension.Substring(0, Math.Min(strFileNameWithoutExtension.Length, 20)).Trim() + "_" + Guid.NewGuid().ToString();
fileUrl = dirUrl + "/" + uniqueFileName + strFileExtension;
uploadVideo.PostedFile.SaveAs(Server.MapPath(fileUrl));
}
using (SqlCommand cmd = new SqlCommand())
{
bool IsUrl = String.IsNullOrEmpty(fileUrl);
fileUrl = String.IsNullOrEmpty(fileUrl) ? txtYoutubeUrl.Text : fileUrl;
if (!String.IsNullOrEmpty(fileUrl))
{
//cmd.CommandText ="insert into tblVideo(CategoryId, StateId, DistrictId, Title, Description, PublishStatus, IsBanner, IsMustReasd, IsHomeRightSide, VideoUrl, IsUrl) values (@CategoryId, @StateId, @DistrictId, @Title, @Description, @PublishStatus, @IsBanner, @IsMustReasd, @IsHomeRightSide, @VideoUrl, @VideoUrl,@IsUrl)";
cmd.CommandText = "insert into tblVideo(CategoryId,StateId,DistrictId,Title,Description,PublishStatus,IsBanner,IsMustReasd,IsHomeRightSide,VideoUrl,IsUrl) values (@CategoryId,@StateId,@DistrictId,@Title,@Description,@PublishStatus,@IsBanner,@IsMustReasd,@IsHomeRightSide,@VideoUrl,@IsUrl) ";
cmd.Parameters.AddWithValue("@CategoryId", ddlCategory.SelectedIndex);
cmd.Parameters.AddWithValue("@StateId", ddlState.SelectedIndex);
cmd.Parameters.AddWithValue("@DistrictId", ddlDistrict.SelectedIndex);
cmd.Parameters.AddWithValue("@Title", txtTitle.Text);
// cmd.Parameters.AddWithValue("@Description", txtDescription.Text);
cmd.Parameters.AddWithValue("@Description", txtDescription.Text);
cmd.Parameters.AddWithValue("@PublishStatus", ddlStatus.SelectedValue);
cmd.Parameters.AddWithValue("@IsBanner", chkBanner.Checked);
cmd.Parameters.AddWithValue("@IsMustReasd", chkMustRead.Checked);
cmd.Parameters.AddWithValue("@IsHomeRightSide", chkRightNews.Checked);
cmd.Parameters.AddWithValue("@VideoUrl", fileUrl);
cmd.Parameters.AddWithValue("@IsUrl", IsUrl);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
else
{
lblMsg.Text = "Choose File";
}
}
}
}
catch(Exception ex)
{
throw ex;
}
}