Kamis, 31 Desember 2015

Goodbye 2015 & Welcome to New Year 2016 : Blog review in past year

Every year this moment of time comes when we have to say ‘bye.. bye..’ to the current year and welcome to the New Year. 

Let’s say goodbye to oldies but good things will be remain with us.It’s seems to be all old days are not good and not bad as well but tomorrow could be good better than previous .So welcome it with full of gusto and have ultimate fun. Don’t bring your 2015 issues into 2016 have a new mind set to do new things for the New Year. Goodbye 2015 & Welcome to New Year 2016.



Really thanks to all my friends, family members, blog visitors and other known/unknown persons with whom I am connected indirectly.Thank you everyone for everything that you gave in my life and the help that you provided lot of encouragement to wrote articles in my blog.

The year 2015 was great favor for me and my real blogging is started from this year. I wrote a no. of articles on my blogMicrosot Technet Blog,MSDN code sample gallery, and  C# corner.Keeping myself busy with my office work as well as with my blog.Thanks for all your support and feedback to my articles.And finally the year 2015 was ended with love, happiness and all your support.  

Let's have a look at our blog reviews in past years.

Awards:
 C# Corner Awards:
  1. C# Corner MVP Award (2014-15)
  2. December 2014 Month Winner
  3. November 2014 Month Winner
Downloads:
   1. Total blog downloads: more than 49,700+ views
   2. Total PageViews: 279500+
Google+:
   1. Total pageviews: more than 1,383,095+ views
MSDN Profile:
   1. Total Points: more than 21000+ points
Twitter Profile:
Top 10 feedbacks from twitter since last year.


The year 2015 is over, we learn many things in 2015 and let us learn more things in this new year 2016 and deliver our best to work. Every end is just a new beginning. Keep your spirits and determination unshaken and you shall always walk the glory road. With courage, faith and efforts you shall conquer everything you desire.Counting my blessings, wishing you more. Hope you enjoy the New Year in store.Have a joyous New Year, my dear friends.

Have a nice day by  :)



Minggu, 27 Desember 2015

WindowsPhone Silverlight (8.0 & 8.1) : Upload files to SFTP Server (C# - XAML)

Introduction:

In previous article, I was explained about "Uploading files to FTP server" and this article can explain about "How to access SFTP server from windows phone programming"

This article can explained about below topics:
1. What is SFTP and Why?
2. How to Setup SFTPServer in Windows 8.0/8.1/10 OS system?
3. How to Connect SFTP Server from WindowsPhone?
4. Upload files to SFTP Server

Requirements:

  • This sample is targeted for windowsphone silverlight 8.1 OS,So make sure you’ve downloaded and installed the Windows Phone 8.1 SDK. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows or Later.

Description:

1. What is SFTP and Why?
  • FTP, or "File Transfer Protocol" is a popular method of transferring files between two remote systems.
  • SFTP, which stands for SSH File Transfer Protocol, or Secure File Transfer Protocol, is a separate protocol packaged with SSH that works in a similar way over a secure connection. The advantage is the ability to leverage a secure connection to transfer files and traverse the filesystem on both the local and remote system.
In almost all cases, SFTP is preferable to FTP because of its underlying security features and ability to piggy-back on an SSH connection. FTP is an insecure protocol that should only be used in limited cases or on networks you trust.

Although SFTP is integrated into many graphical tools, this guide will demonstrate how to use it through its interactive command line interface.

2. How to Setup SFTP Server in Windows 8.0/8.1/10 OS system?
It is very easy to setup SFTP server, and please get guidance from WinSCP official website from here

3. Upload files to SFTP server
Fortunately for windows phone silverlight, We already Have SSH.NET library which support to access SFTP server from windows phone. But still there is little bit issues while SFTP connections. And after lots of research finally i made working binary(DLL) file for windows phone silverlight. 
Step 1:
1. Open Microsoft Visual Studio Express 2013 for Windows (or) later.
2. Create new silverlight project using the "Blank App" template available under Visual C# -> Store Apps -> Windows Phone Apps. (for example project name :WindowsPhoneSFTP)
Step 2:
Recently i made one binary file for SFTP on windows phone programming, and temporarily now i can directly add SFTP binary file to reference folder to access SFTP server using windows phone 8.0 silverlight C#.
Step 3: 
Now add below method for uploading files to SFTP server.
  • public async Task<string> SFTPFileUpload(string FileContent, string fileUsername)  
  •         {  
  •             try  
  •             {  
  •                 string FolderPath = "FTPFiles/WindowsPhone";  
  •                 string m_Host = "Server Name/IP Address";  
  •                 string FtpUserName = "SFTP server username";  
  •                 string FtpPwd = "SFTP Password";  
  •                 int SFtpPort = 22;//Default IP address  
  •                 fileUsername = fileUsername + ".txt";  
  •                 SftpClient sftp = new SftpClient(m_Host, SFtpPort, FtpUserName, FtpPwd);  
  •                 sftp.ConnectionInfo.Timeout = TimeSpan.FromSeconds(6000);  
  •   
  •                 sftp.Connect();  
  •                 sftp.ChangeDirectory(FolderPath);  
  •                 byte[] data = Encoding.Unicode.GetBytes(FileContent);  
  •                 sftp.BufferSize = 4 * 1024;  
  •   
  •                 Stream fileStream = new MemoryStream(data);  
  •   
  •                 sftp.UploadFile(fileStream, fileUsername, null);  
  •   
  •                 return "Success";  
  •             }  
  •             catch (Exception ex)  
  •             {  
  •                 ShellToast toast = new ShellToast();  
  •                 toast.Title = ex.Message.ToString();  
  •                 toast.Content = DateTime.Now.ToString();  
  •                 toast.Show();  
  •                 return ex.Message;// "Server is not connected.";  
  •             }  
  •         }  

  • Now we can use above method like below:
    1. private async void BtnSubmit_Click(object sender, RoutedEventArgs e)  
    2.         {  
    3.             var Result = await SFTPFileUpload("Hi My FileText""MyFile");  
    4.             TbckUploadStatus.Text = "File upload: " + Result;  
    5.         }  

    And add below xaml code in MainPage.xaml
    1. <!--LayoutRoot is the root grid where all page content is placed-->  
    2.     <Grid x:Name="LayoutRoot" Background="White">  
    3.         <Grid VerticalAlignment="Center">  
    4.         <Grid.RowDefinitions>  
    5.             <RowDefinition Height="Auto"/>  
    6.             <RowDefinition Height="*"/>  
    7.         </Grid.RowDefinitions>  
    8.         <Button Name="BtnSubmit" VerticalAlignment="Center" Content="Upload to SFTP" Background="#FF58E277" Click="BtnSubmit_Click"/>  
    9.         <TextBlock Name="TbckUploadStatus" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="Black"/>  
    10.         </Grid>  
    11.     </Grid>  

    Output:

    WindowsPhoneSFTP
    FeedBack Note:

    Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

    Follow me always at  
    Have a nice day by  :)

    WindowsPhone Silverlight (8.0 & 8.1) : Upload files to Ftp Server (C# - XAML)

    Introduction:

    I am very happy to write an article about FTP server access from windows phone programming using c#.net, there are no direct APIs available for leveraging FTP services in a Windows phone app. From an enterprise perspective, this makes it rather difficult for employees to access files over their phones. Fortunately we have socket support for windows phone to communicate with a multitude of different services, making users feel more connected and available than ever.


    This article can explained about below topics:
    1. What is FTP and Why?
    2. How to Setup Ftp Server in Windows 8.0/8.1/10 OS system?
    3. How to Connect FTP Server from WindowsPhone?
    4. Upload files to Ftp Server

    Requirements:

    • This sample is targeted for windowsphone silverlight 8.1 OS,So make sure you’ve downloaded and installed the Windows Phone 8.1 SDK. For more information, see Get the SDK.
    • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
    • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows or Later.

    Description:

    1. What is FTP and Why?

    • The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files from one host to another host over a TCP-based network, such as the Internet.
    •  FTP is built on a client-server architecture and uses separate control and data connections between the client and the server.
    • FTP users may authenticate themselves with a clear-text sign-in protocol, normally in the form of a username and password, but can connect anonymously if the server is configured to allow it.
    • For secure transmission that protects the username and password, and encrypts the content, FTP is often secured with SSL/TLS (FTPS). SSH File Transfer Protocol (SFTP) is sometimes also used instead, but is technologically different.
    2. How to Setup Ftp Server in Windows 8.0/8.1/10 OS system?

    This section is not applicable for windows app developer, but it is better to learn understand the FTP communication by creating server in your machine.
    2.1. So open Programs and Features in Control panel. Click on ‘Turn Windows features on or off’ as shown below.

    If IIS was not installed earlier on particular Windows 8 or 8.1 computer, you need to install other features of IIS too ( as shown by arrow marks). See the below screenshot for the actual requirements to run FTP server on Windows 8/8.1 (All features which are ticked need to be installed).

    Note: You must be restart your machine for above step to make changes in your . 

    2.2. After installation is completed, search and open ‘Internet Information Services (IIS) Manager’ in Administrator mode from start menu.


    Expand the sites, right click on it and ‘Add FTP Site’

    2.3. Give a name for FTP site and browse the local folder which you need to give access to others through server.(I already created a folder called 'FTPShare' on C drive before reaching this step.)


    2.4. In next screen you need to select the local computer’s IP address from drop down box. I hope you have already set up static IP for the computer.


    Under SSL option, select No SSL to make the connection without SSL certificate. In production environment for professional FTP server setup, you may need to enable SSL which requires a certificate.

    Now its time to Set Up FTP Access Permission on Windows 8 or 8.1 or Windows 10

    2.5. In next screen you can set the permission for users to access the FTP site. Here you need to decide how others will be accessing the FTP share and who will be having Read-only or Read & Write access.

    Let’s assume this scenario, you want specific users to have read and write access, so obviously they must type an user name and password for it. Other users can access the FTP site without any username or password to view the content only, it’s called anonymous users access.

    You will find several ways to do this, but here is the simple way which worked for me.

    Firstly open start menu and type 'lusrmgr.msc', and create a user on Windows 8 or Windows 10 local computer (if you are not using active directory environment) .


    and add the users who will be having read and write access on FTP site. In this example I have created ‘ftpusers’ group and added required users inside it.

    2.6. Now, let’s continue the FTP site settings. In next screen to give the permission, select ‘Basic’ which will be prompting for user name and password, select Specified  roles or groups option from drop down and type the correct group name. Set Read and Write permission for the group.
    Press Finish to complete the setup.
    Check the Firewall ! It should allow FTP traffic.

    We are almost done and completed the all necessary steps. Now, you need to either disable the firewall or allow FTP inbound and outbound traffic on Windows 8 or 8.1 computer. I hope you can do it easily.

    3. How to Connect FTP Server from WindowsPhone?

    Step 1:
    1. Open Microsoft Visual Studio Express 2013 for Windows (or) later.
    2. Create new silverlight project using the "Blank App" template available under Visual C# -> Store Apps -> Windows Phone Apps. (for example project name :WindowsPhoneFTP)
    Step 2:
    Recently i made one binary file for FTP on windows phone programming, and temporarily now i can directly add ftp binary file to reference folder to access FTP server using windows phone 8.0 silverlight C#.
    Step 3: 
    Now add below helper class for uploading files to FTP server.
    1. public class FtpClientClass  
    2.     {  
    3.         private static string m_Host = "Please ENTER your Server Name/IP";  
    4.         private static string FtpUserName = "Server UserName";  
    5.         private static string FtpPwd = "Server Password";  
    6.         private static string FtpPort = "21";  
    7.         private readonly NetworkCredential m_Credentials = new NetworkCredential(FtpUserName, FtpPwd);  
    8.   
    9.         private const string PathToSet = "/";  
    10.   
    11.         private const string FolderToCreate = "";//"WindowsPhone"; 
    12.         public FtpClient CreateFtpClient()  
    13.         {  
    14.             
    15.             var ftpClient = new FtpClient();  
    16.             ftpClient.Credentials = m_Credentials;  
    17.             ftpClient.HostName = new HostName(m_Host);  
    18.             ftpClient.ServiceName = FtpPort;  
    19.   
    20.             return ftpClient;  
    21.         } 
    22.    
    23.         //Upload file to Ftp Server 
    24.         public async Task<string> UploadFileAsync(string DataFields, string fileUsername)  
    25.         {  
    26.             try  
    27.             {  
    28.                 if (fileUsername=="")  
    29.                 {  
    30.                     fileUsername = "NoUserName";  
    31.                 }  
    32.                 System.Diagnostics.Debug.WriteLine("-----------------------------------");  
    33.                 System.Diagnostics.Debug.WriteLine("TestCreateFileAsync");  
    34.                 System.Diagnostics.Debug.WriteLine("-----------------------------------");  
    35.   
    36.                 var ftpClient = CreateFtpClient();  
    37.   
    38.                 await ftpClient.ConnectAsync();  
    39.                 await ftpClient.CreateDirectoryAsync(PathToSet + FolderToCreate);  
    40.                 string testFilePath = PathToSet + fileUsername + ".txt";  
    41.   
    42.                 using (var stream = await ftpClient.OpenWriteAsync(testFilePath))  
    43.                 {  
    44.                     var bytes = Encoding.UTF8.GetBytes(DataFields);  
    45.   
    46.                     await stream.WriteAsync(bytes.AsBuffer());  
    47.                     await stream.FlushAsync();  
    48.                 }  
    49.                 //await ftpClient.DisconnectAsync();  
    50.                 return "Success";  
    51.             }  
    52.             catch(Exception ex)  
    53.             {  
    54.                 return ex.Message;  
    55.             }  
    56.         }  
    57.     }  
    Now we can use above helper class like below:
  • using System;  
  • using System.Collections.Generic;  
  • using System.Linq;  
  • using System.Net;  
  • using System.Windows;  
  • using System.Windows.Controls;  
  • using System.Windows.Navigation;  
  • using Microsoft.Phone.Controls;  
  • using Microsoft.Phone.Shell;  
  • using WindowsPhoneFTP.Resources;  
  •   
  • namespace WindowsPhoneFTP  
  • {  
  •     public partial class MainPage : PhoneApplicationPage  
  •     {  
  •         // Constructor  
  •         public MainPage()  
  •         {  
  •             InitializeComponent();  
  •         }  
  •         private void BtnSubmit_Click(object sender, RoutedEventArgs e)  
  •         {  
  •             UploadFile_FTP();  
  •         }  
  •         private async void UploadFile_FTP()  
  •         {  
  •             FtpClientClass ObjFtpClientClass = new FtpClientClass();  
  •             var Result = await ObjFtpClientClass.UploadFileAsync("Hi My FileText""MyFile");  
  •             TbckUploadStatus.Text = "File upload: "+Result;
  •         }  
  •   
  •     }  
  • }  

  • And add below xaml code in MainPage.xaml
    1. <!--LayoutRoot is the root grid where all page content is placed-->  
    2.     <Grid x:Name="LayoutRoot" Background="White">  
    3.         <Grid VerticalAlignment="Center">  
    4.         <Grid.RowDefinitions>  
    5.             <RowDefinition Height="Auto"/>  
    6.             <RowDefinition Height="*"/>  
    7.         </Grid.RowDefinitions>  
    8.         <Button Name="BtnSubmit" VerticalAlignment="Center" Content="Upload to FTP" Background="#FF58E277" Click="BtnSubmit_Click"/>  
    9.         <TextBlock Name="TbckUploadStatus" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="Black"/>  
    10.         </Grid>  
    11.     </Grid>  

    Output:
    WindowsPhoneFTP

    If you want to access SFTP server from windows phone silverlight, you can read it on next article from here.

    FeedBack Note:
    Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

    Follow me always at  
    Have a nice day by  :)