European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET Core 1.0 Hosting - HostForLIFE.eu :: How to Get Youtube Video Thumbnail image in ASP.NET?

clock March 31, 2016 23:15 by author Peter

This tutorial will show you how to get youtube video thumbnail image in ASP.NET. Write the following code that returns image thumbnail url of given youtube video url by passing video url as a parameter in getYouTubeThumbnail method.

public string getYouTubeThumbnail(string YoutubeUrl)   
{   
    string youTubeThumb=string.Empty;   
    if (YoutubeUrl == "")   
        return "";   
 
    if (YoutubeUrl.IndexOf("=") > 0)   
    {   
        youTubeThumb = YoutubeUrl.Split('=')[1];   
    }   
    else if (YoutubeUrl.IndexOf("/v/") > 0)   
    {   
        string strVideoCode = YoutubeUrl.Substring(YoutubeUrl.IndexOf("/v/") + 3);   
        int ind = strVideoCode.IndexOf("?");   
        youTubeThumb = strVideoCode.Substring(0, ind == -1 ? strVideoCode.Length : ind);   
    }   
    else if (YoutubeUrl.IndexOf('/') < 6)   
    {   
        youTubeThumb = YoutubeUrl.Split('/')[3];   
    }   
    else if (YoutubeUrl.IndexOf('/') > 6)   
    {   
        youTubeThumb = YoutubeUrl.Split('/')[1];   
    }   
 
    return "http://img.youtube.com/vi/" + youTubeThumb + "/mqdefault.jpg";   
}   

You may call the above function with various youtube url format like,
getYouTubeThumbnail("http://youtu.be/4e3qaPg_keg");   
getYouTubeThumbnail("http://www.youtube.com/watch?v=bvLaTupw-hk");

HostForLIFE.eu ASP.NET Core 1.0 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



ASP.NET 4.5 Hosting - HostForLIFE.eu :: How to Create a Database With Data Source Control in ASP.NET

clock March 29, 2016 21:10 by author Anthony

In this post we are going to talk about techniques for displaying data contained in the SQL Server database with ASP.NET. There are at least three ways commonly used to perform the data binding to server conrol in ASP.NET 4.5

Here are three ways:

  • Data Source Control (Declarative)
  • Code by Hand
  • Model Binding

but in this time I will explain how to create a database with the Data Source Control in ASP.NET 4.5


Web Config

Before going into the main discussion helps me informed beforehand that the connection string that is used to communicate with the database in ASP.NET contained in the configuration file "web.config". Here are the contents

file: Web.config


<?xml version="1.0"?>
<configuration>

<connectionStrings>
<add name="learn_webConnectionString" connectionString="Data Source=SOFT-ENGINEER;Initial Catalog=learning_web;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>


Database Design

The database used in this post only use one of the table is very simple with the name "Category"

Data Source Control

Data Source Control in ASP.NET 4.5 used as a link between the database with controls for displaying data. Using this approach means that we do is get the data in a declarative rather than programmatic. To be more explicit, the following is a sample code

file: default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TryingWebForm.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Data Source Control</title>

</head>
<body>

<form id="form1" runat="server">

<div>

<p>The Declarative Way</p>

<asp:SqlDataSource ID="sdsCategory" runat="server" ConnectionString="<%$ ConnectionStrings:trying_webConnectionString %>"

SelectCommand="SELECT [id], [name_category] FROM [Category]"/>

<asp:GridView ID="gvCategoryDeclarative" runat="server" DataSourceID="sdsCategory" />

</div>

</form>

</body>

</html>

As seen in the above code, control "SqlDataSource" requires a connection string and a query command to be executed. In magic this control will connect to the database and execute commands query and the result was thrown into "GridView" by filling property "DataSourceID" with the Id of control SqlDataSource concerned. The image below is the result

 

HostForLIFE.eu ASP.NET 4.5 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.0 Hosting - HostForLIFE.eu :: How to Upload File to SFTP Server using free Utility WINSCP?

clock March 2, 2016 21:45 by author Peter

In this tutorial, I will describe a technique for uploading a file to sftp server using third party tools WinSCP. WinSCP is an open source free SFTP client, FTP client, WebDAV client and SCP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.

Features

  • Graphical user interface
  • Translated into many languages
  • Integration with Windows (drag&drop, URL, shortcut icons, jump list)
  • All common operations with files
  • Support for SFTP and SCP protocols over SSH and FTP and WebDAV protocols
  • Batch file scripting and command-line interface and .NET assembly for advanced programming tasks
  • Directory synchronization in several semi or fully automatic ways
  • Integrated text editor
  • Shares site settings with PuTTY
  • Support for password, keyboard-interactive, public key and Kerberos (GSS) authentication
  • Integrates with Pageant (PuTTY authentication agent) for full support of public key authentication with SSH
  • Explorer and Commander interfaces
  • Optionally protects stored site information with master password
  • Optionally supports portable operation using a configuration file in place of registry entries, suitable for operation from removable media

Now, write the following code:
private static void UploadToSFTP(string stringJasontext) 

try 

    //get static value from App.config file. 
    string ftpServerIP = ConfigurationSettings.AppSettings["sftpServerIP"].ToString(); 
    string stringsFtpUserID = ConfigurationSettings.AppSettings["sftpUserID"].ToString(); 
    string stringsFtpPassword = ConfigurationSettings.AppSettings["sftpPassword"].ToString(); 
    string stringStrDate = System.DateTime.Now.ToString("dd_MM_yyyy-hh_mm_ss"); 
    string stringFileName = "LeaseJson_" + stringStrDate + ".json"; 
    string stringFromPath = ConfigurationSettings.AppSettings["sFromPath"].ToString(); 
    string stringToPath = ConfigurationSettings.AppSettings["sToPath"].ToString(); 
    string stringHostKey = ConfigurationSettings.AppSettings["sHostKey"].ToString(); 
    string stringsBackUpFolder = "Processed"; 
    //create folder for back up data 
    if (!Directory.Exists(stringFromPath + stringsBackUpFolder)) 
    { 
          Directory.CreateDirectory(stringFromPath + stringsBackUpFolder); 
    } 
    //check whether file exist or not in local machine. 
    if (!System.IO.File.Exists(stringFromPath + stringFileName)) 
    { 
          using (FileStream fileStreamLocalFile = File.Create(stringFromPath + stringFileName)) 
          { 
                byte[] byteLocalFile = new UTF8Encoding(true).GetBytes(stringJasontext); 
                fileStreamLocalFile.Write(byteLocalFile, 0, byteLocalFile.Length); 
          } 
    } 
    SessionOptions sessionOptionsSFTP = new SessionOptions 
    { 
          Protocol = Protocol.Sftp, 
          HostName = ftpServerIP, 
          UserName = stringsFtpUserID, 
          Password = stringsFtpPassword, 
          PortNumber = 22, 
          SshHostKeyFingerprint = stringHostKey 
    }; 
    WinSCP.Session sessionSFTP = new WinSCP.Session(); 
    sessionSFTP.Open(sessionOptionsSFTP); 
    TransferOptions transferOptionsSFTP = new TransferOptions(); 
    transferOptionsSFTP.TransferMode = TransferMode.Binary; 
    transferOptionsSFTP.FilePermissions = null; 
    transferOptionsSFTP.PreserveTimestamp = false; 
    transferOptionsSFTP.ResumeSupport.State = TransferResumeSupportState.Off; 
    TransferOperationResult transferOperationResultSFTP; 
    transferOperationResultSFTP = sessionSFTP.PutFiles(stringFromPath + stringFileName, stringToPath, false, transferOptionsSFTP); 
    if (System.IO.File.Exists(stringFromPath + stringFileName)) 
    { 
          File.Move(stringFromPath + stringFileName, stringFromPath + "\\" + stringsBackUpFolder + "\\" + stringFileName); 
    } 
    transferOperationResultSFTP.Check();

    if (transferOperationResultSFTP.IsSuccess == true) 
    { 
          Console.Write("File upload successfully"); 
    } 
    else 
    { 
          Console.Write("File upload failed"); 
    } 


catch (Exception exError) 

    Console.Write(exError.Message); 


#endregion 
#region Upload File to FTP server as Json File 
//private static void UploadToFTP(string stringJasontext) 
//{ 
// try 
// { 
// string stringFtpUserID = ConfigurationSettings.AppSettings["ftpUserID"].ToString(); 
// string stringFtpPassword = ConfigurationSettings.AppSettings["ftpPassword"].ToString(); 
// string stringStrDate = System.DateTime.Now.ToString("dd_MM_yyyy-hh_mm"); 
// string stringToPath = ConfigurationSettings.AppSettings["ToPath"].ToString() + "LeaseJson_" + stringStrDate + ".json"; 
// FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(stringToPath); 
// ftpWebRequest.Credentials = new NetworkCredential(stringFtpUserID, stringFtpPassword); 
// ftpWebRequest.KeepAlive = false; 
// ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile; 
// ftpWebRequest.UseBinary = true; 
// ftpWebRequest.ContentLength = stringJasontext.Length; 
// ftpWebRequest.Proxy = null; 
// using (Stream TempStream = ftpWebRequest.GetRequestStream()) 
// { 
// System.Text.ASCIIEncoding TempEncoding = new System.Text.ASCIIEncoding(); 
// byte[] byteTempBytes = TempEncoding.GetBytes(stringJasontext); 
// TempStream.Write(byteTempBytes, 0, byteTempBytes.Length); 
// } 
// ftpWebRequest.GetResponse(); 
// } 
// catch (Exception exError) 
// { 
// Console.Write(exError.Message); 
// } 
//} 
#endregion 

 

HostForLIFE.eu ASP.NET Core 1.0 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in