Minggu, 27 Desember 2015

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  :)


    Minggu, 20 Desember 2015

    Cara Pasang Video Youtube Responsive di Blog

    Cara Pasang Video Youtube Responsive di Blog

    Artikel ini saya buat karena saya memiliki pengalaman kurang baik ketika menyertakan script video youtube di Blog yang saya anggap kurang responsive. Script saya ambil dari fitur embed video yang bisa sobat tambahkan dan dapat ditonton langsung di blog. Namun dengan menambahkan video tersebut akan mengurangi nilai SEO sebuah blog karena adanya elemen iframe yang membuat tampilannya pun belum responsive jika ukuran layar diperkecil. Script bermanfaat ini saya dapat dari Mbak Arlina Fitriyani yang cantik dan seorang ahli desain Web ternama Indonesia.


    Cara Membuat Video Youtube Menjadi Responsive di Blog

    Berikut cara penerapannya :

    1. Buka Blogger >> Template >> Edit HTML >> Tambahkan kode di bawah ini
    sebelum ]]></b:skin> atau </style>


    BLOGGINGPASURUAN - CSS

    /* Responsive Youtube for blogger  */
    .videoyoutube{text-align:center;margin:auto;width:100%;}
    .video-responsive{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;}
    .video-responsive iframe{position:absolute;top:0;left:0;width:100%;height:100%;border:0}


    2. Tambahkan kode di bawah ini sebelum </body>


    BLOGGINGPASURUAN - HTML/Java Script

    <script type='text/javascript'>
    //<![CDATA[
    // Youtube Responsive
    setTimeout(function(){$(".video-youtube").each(function(){$(this).replaceWith('<iframe class="video-youtube loader" src="'+$(this).data("src")+'" allowfullscreen="allowfullscreen" height="281" width="500"></iframe>')})},5e3);
    //]]>


    3. Simpan template.

    4. Selanjutnya untuk menambahkan video pada postingan, gunakan kode di bawah ini


    BLOGGINGPASURUAN - HTML

    <div class="videoyoutube">
    <div class="video-responsive">
    <div class="video-youtube loader" data-src="MASUKKAN-LINK-EMBED-VIDEO-DI-SINI">
    </div>
    </div>
    </div>


    Berikut ini cara mengambil dan masukkan Link YouTube 

    Cara Pasang Video Youtube Responsive di Blog


    5. Terakhir simpan / publikasikan postingan.



    Cara Agar Youtube Tampil Responsive di Blog dengan CSS

    Masukkan kode dibawah ini di atas kode ]]></b:skin>atau </style>


    BLOGGINGPASURUAN - CSS

    /* CSS for YouTube Resposive Video on Blogger*/
    .post-body iframe{width:100%!important;}
    @media screen and (max-width:960px){
    .post-body iframe{max-height:90%}}
    @media screen and (max-width:768px){
    .post-body iframe{max-height:75%}}
    @media screen and (max-width:600px){
    .post-body iframe{max-height:60%}}
    @media screen and (max-width:480px){
    .post-body iframe{height:auto!important;max-height:auto!important}}


    Anda bisa mengatur sendiri CSS max-height dalam media query jika kurang sesuai.

    Video youtube yang Anda pasang di postingan sudah responsive yang berarti video bisa menyesuaikan dengan ukuran dalam layar apapun. Semoga bermanfaat…

    Jumat, 18 Desember 2015

    Mengatasi Blue Screen WINDOWS dan Apa Penyebabnya

    Blue screen of death  - atau BSOD – menjadi pemandangan yang tidak mengenakkan ketika kita sedang sibuk dengan pekerjaan menggunakan komputer atau laptop. BSODs muncul ketika Microsoft Windows menemukan kesalahan kritis dan kadang tidak terselesaikan hanya dengan me-reboot komputer atau laptop.

    Blue screen atau BSOD adalah jenis kesalahan terburuk yang sering dialami pada komputer atau laptop, BSOD tidak seperti error pada aplikasi yang hanya mempengaruhi kenerja aplikasi tersebut saja dan bukan sistem windows secara keseluruhan. BSOD terjadi juga bisa dikarenakan crash perangkat lunak atau softwarenya dan juga kerusakan pada perangkat keras atau hardwarenya.


    Catatan : Jika itu disebabkan oleh software, dapat dipastikan software yang digunakan tidak ORI atau umum disebut CRACK. Apalagi jika menggunakan OS Crack ini akan jauh lebih parah artinya masalah blue screen akan lebih sering dialami. Jika itu terjadi pada hardware-nya ini bisa desebabkan usia hardware dan juga bisa disebabkan penggunaan yang terlalu berlebihan tanpa diimbangi dari sisi maintanance atau perawatan… umumnya sering dialami oleh PC di kantor kantor.


    Apa Penyebab Blue Screen atau BSOD

    Layar biru atau blue screen umumnya disebabkan oleh masalah dengan hardware , software, atau driver hardware-nya. Perangkat lunak ( software ) standar seharusnya tidak menyebabkan blue screen - jika aplikasi crash aplikasi akan melakukannya perbaikan /updater tanpa mempengaruhi ( sistem operasi ) OS-nya. Jika Blue screen  disebabkan oleh masalah hardware dan masalah dengan perangkat lunak tingkat rendah berjalan di kernel Windows.

    Blue screen terjadi ketika Windows bertemu dengan "UNREG ERROR." Kegagalan kritis ini menyebabkan Windows crash dan berhenti bekerja. Satu-satunya hal yang umum dilakukan pada Windows adalah hentikan komputer dan restart. Hal ini dapat menyebabkan kehilangan data, karena program tidak memiliki kesempatan untuk menyimpan data Anda pada saat itu - idealnya, program harus terus menyimpan data secara otomatis walaupun ketika problem blue screen terjadi..andaikan masih bisa menyimpan umumnya data-pun menjadi corrupt atau rusak.

    Ketika Blue screen terjadi, Windows secara otomatis membuat "Minidump" file yang berisi informasi tentang kesalahan atau penyebab error dan menyimpannya ke disk Anda. Anda dapat melihat informasi tentang minidumps ini untuk membantu mengidentifikasi penyebab layar biru.

    Mengatasi Blue Screen WINDOWS dan apa Penyebabnya



    Restart Windows Ketika Blue Screen Muncul

    Secara default, Windows akan secara otomatis me-restart komputer setiap kali bertemu dengan blue screen. Jika Anda ingin melihat pesan kesalahan yang lebih rinci setiap kali blue screen muncul, Anda dapat menonaktifkan reboot otomatis pada BSODs dari Windows Control Panel.

    Mengatasi Blue Screen WINDOWS dan apa Penyebabnya



    Melihat informasi BSOD atau Blue Screen

    Aplikasi BlueScreenViewgratis NirSoft ini menawarkan cara mudah untuk melihat informasi layar biru. Ini akan memindai semua file Minidump yang dibuat selama BSODs dan menampilkan informasi kesalahan yang menjadi penyebab Blue screen.

    Mengatasi Blue Screen WINDOWS dan apa Penyebabnya


    Informasi ini juga tersedia di Windows Event Viewer, di mana pesan layar biru yang tersebar di antara aplikasi crash dan pesan log sistem lainnya. Jika Anda ingin debug dump memori, cobalah Microsoft WinDbg debugger. Untuk mencoba memperbaiki Blue scree.



    Cara Mengatasi BSOD atau Blue Screen

    Pada Windows 7 dan versi yang lebih baru dari Windows, informasi blue-screen juga ditampilkan dalam Action Center. Jika Anda mengalami blue screen, Anda dapat membuka Action Center dan memeriksa solusi. Windows akan menganalisis BSODs dan jenis-jenis kesalahan sebelum memberikan Anda informasi bagaimana cara mengatasi masalah BSOD atau blue screen.


    Mengatasi Blue Screen WINDOWS dan apa Penyebabnya


    Anda bisa mendapatkan informasi tentang kesalahan blue screen dengan pesan kesalahan tertentu misalnya seperti "DRIVER_IRQL_NOT_LESS_OR_EQUAL", Pesan blue screen pada Windows 8 akan meminta Anda untuk melakukan pencarian web untuk pesan kesalahan tersebut kemudian mempelajari bagaimana cara menyelesaikannya.



    Tips Bermanfaat Berkaitan dengan Masalah Blue Screen atau BSODs

    BSODs memiliki berbagai akar penyebab, tetapi tips ini akan banyak membantu Anda dengan maslah yang berkaitan dengan blue screen:

    √ Gunakan System Restore: Jika sistem Anda pertama kali mengalami blue screen, gunakan System Restore untuk mengembalikan sistem  perangkat lunak kembali ke keadaan sebelumnya. Jika berhasil, berarti masalah blue screen pada PC atau laptop masalahnya adalah terkait dengan software.

    √  Scaning Malware:Malware akan lebih jauh masuk ke sistemnya Windows dan masuk ke dalam kernel Windows pada tingkat yang rendah dapat menyebabkan ketidakstabilan sistem pada komputer Anda.

    Tips : Jika Anda menggunakan Anti Virus free ( apapun ) silahkan scanning pada posisi safe mode ( boot time scan ) ini akan lebih effektif dalam mengidentifikasi malware atau virus virus yang lain.


    Mengatasi Blue Screen WINDOWS dan apa Penyebabnya


    √ Update Driver dan install : Driver yang tidak secara otomatis terupdate dapat menyebabkan crash. Silahkan download driver terbaru untuk hardware komputer Anda dari situs web produsen resminya kemudian menginstalnya - ini bisa memperbaiki BSODs yang disebabkan oleh masalah driver.

    √ Boot Ke Safe Mode: Jika komputer Anda sering mengalami blue screen tiap kali dinyalakan, coba boot ke safe mode ( ini penting ). Dalam safe mode Windows hanya driver penting yang bekerja. Jika driver yang terpasang menyebabkan blue screen pada Windows, seharusnya tidak terjadi ketika Anda membuka Windows pada posisi SAFE MODE. Anda dapat memperbaiki permasalahan blue screen pada posisi safe mode ini.

    √  Periksa Masalah Hardware: Blue Screen ( BSOD ) dapat disebabkan oleh hardware yang rusak di komputer Anda. Coba menguji memori komputer Anda untuk kesalahan yang mungkin terjadi pada gardware komputer atau laptop dan periksa suhu untuk memastikan bahwa itu tidak terlalu panas.

    √ Menginstal ulang Windows: Meng-install ulang Windows adalah opsi terakhir. Ini akan mengembalikan posisi software ke keadaan awal atau sistem yang ada, menggantinya dengan sistem Windows yang lebih segar. Jika komputer Anda masih mengalami masalah blue screen, Anda mungkin memiliki masalah hardware.


    Kesimpulan

    Sebuah komputer dalam keadaan bekerja seharusnya tidak mengalami Blue Screen atau BSOD jika perangkat lunak atau perangkat keras dalam kondisi sempurna. Namun bisa jadi laptop atau komputer yang berfungsi dengan baik mengalami blue screen ( namun ini sangat jarang terjadi ) tanpa alasan yang jelas - ini mungkin disebabkan dari bug driver atau masalah hardware.

    Jika komputer Anda sering mengalami blue screen, berarti terjadi masalah pada komputer atau laptop Anda. Jika Anda menemukan blue screen se-sekali dalam kurun waktu yang lama ( 1-2 tahun), jangan khawatir tentang hal itu….namun Anda harus tetap berusaha memperbaikinya walaupun itu hanya gejala awal dari ketidak beresan pada software atau hardware

    Semoga bermanfaat..

    Selasa, 08 Desember 2015

    Cara Mudah Menghapus Broken Link “ERROR 404”

    Cara Mudah Menghapus Broken Link “ERROR 404”

    Beberapa minggu yang lalau saya mempublikasikan artikel “ Cara Cepat Menemukan dan Menghapus Broken Links “. Namun kali ini saya juga ingin mempublikasikan kembali namun dangan menggunakan Webmaster console ( dulu WebmasterTools ) dan cari ini akan bener bener permanent menghapus broken link atau penyebab terjadinya ERROR 404.


    Penyebab Crawl Error Page Not Found 404

    Yang menjadi penyebab error 404 halaman tidak di temukan pada blog adalah terdapat link yang mengarah pada suata halaman yang terhapus, atau tertuju pada sebuah halaman link yang rusak (broken link) hal tersebut bisa di akibatkan karena kesalahan pengetikan yang mengarah pada sub domain blog, bisa juga di akibatkan karena menghapus halaman blog yang tidak sengaja, atau link tersebut memang sudah kadaluarsa. Biasanya terjadi karena ada sebuah link yang di letakkan oleh seorang komentar pada sebuah blog, link tersebut sudah mati atau rusak, sehingga menimbulkan terjadinya crawl error.



    Cara Menghapus Kode 404 Di Google webmaster Tools


    1.Masuk dan login ke google webmaster tools Anda.

    2. Masuk ke halaman menu di sebelah kiri,Craw – Crawl Error

    Cheklist (centang) pada priority, maka akan otomatis tercentang semua filenya, kemudian klik download, pilih format google docs.

    Cara Mudah Menghapus Broken Link “ERROR 404”


    3.Maka akan terlihat seperti gambar di bawah, silahkan buka notepad copy semua link tersebut


    Cara Mudah Menghapus Broken Link “ERROR 404”



    4. Silahkan buka menu halaman google index – Remove URLs.

    Cara Mudah Menghapus Broken Link “ERROR 404”


    5. Klik “create a new removal request” masukkan satu link yang anda copy pada notepad tadi, terakhir klik “submit request”, lakukan satu demi satu pada link hasil copy pada note pad hingga selesai. Hal ini membutuhkan sedikit kesabaran anda jika terdapat banyak link yang error.

    Cara Mudah Menghapus Broken Link “ERROR 404”


    6.Jika semua sudah selesai, kembali pada menu halaman Crawl – Crawl Error, Cheklist (centang) pada priority dan Klik tombol Mark as fixed.

    Cara Mudah Menghapus Broken Link “ERROR 404”

    7.Pada tahap ini anda sudah selesai,Crawl error 404 akan di proses, sekarang sudah tidak lagi tampak, seperti gambar di bawah.

    Cara Mudah Menghapus Broken Link “ERROR 404”
    Demikian cara mengatasi atau memperbaiki kode Error Page Not Found 404 secara manual akan lebih efektif dan bersifat permanen, sebenarnya hal ini tidak mempengaruhi rangking halaman google, tetapi kita juga harus secepatnya memperbaiki, karena akan berdampak kepada backlink atau proses backlink yang lama pada halaman yang sudah ter index oleh google.

    Semoga bermanfaat…..