Monday, August 16, 2010

C# FAQs Series: How Use FTP Using C#


àIn C# FAQs Series: We discuss most frequent questions asked on C# forums.
As a C# developer you may often have to use FTP. Following is simple program which will demonstrate how to FTP using C#.
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Geting the object used to communicate with the server.
FtpWebRequest FWRrequest = (FtpWebRequest)WebRequest.Create( "ftp://www.mrmubi.com/mytest.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;
// Set network credentials.
FWRrequest.Credentials = new NetworkCredential ("user","password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("myfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
FWRrequest.ContentLength = fileContents.Length;
Stream requestStream = FWRrequest.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("File upload complete , status {0}", response.StatusDescription);
response.Close();
}
}
}
}
How to download file using FTP in C#...
public static bool DisplayFileFromServer(Uri serverUri)
{
    // The serverUri parameter should start with the ftp:// scheme.
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Geting the object used to communicate with the server.
    WebClient WCrequest = new WebClient();
 
    // Credentials
    WCrequest.Credentials = new NetworkCredential ("user","password");
    try 
    {
        byte [] newFileData = WCrequest.DownloadData (serverUri.ToString());
        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        Console.WriteLine(fileString);
    }
    catch (WebException e)
    {
        Console.WriteLine(e.ToString());
    }
    return true;
}
How to delete file using FTP in C#...
public static bool DeleteFileOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    // 
 
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    FtpWebRequest FWRrequest = (FtpWebRequest)WebRequest.Create(serverUri);
    FWRrequest.Method = WebRequestMethods.Ftp.DeleteFile;
 
    FtpWebResponse FWRresponse = (FtpWebResponse) FWRrequest.GetResponse();
    Console.WriteLine("File delete status: {0}",FWRresponse.StatusDescription);  
    FWRresponse.Close();
    return true;
}
You see how easy is it to play with your FTP account in C#.

Friday, August 13, 2010

Microsoft Adaptive Keyboard Prototype - UIST Student Innovation Contest

Microsoft adaptive keyboard, what an excellent idea. This means now we can configure our keyboard as well.
No, it's not the mystery device that Microsoft has been teasing as of late, but we have a feeling that plenty of folks will be wishing that the company's so-called "Adaptive Keyboard" was it. Unfortunately, it's just a prototype, and Microsoft apparently has no plans to turn it into an actual product. It will, however, be landing in the hands of a few lucky students participating in this year's UIST Student Innovation Contest, who will be given free reign to do whatever they like with the keyboard and possibly be rewarded with a $2,000 or $500 prize for their hard work. As for the keyboard itself, it's basically Microsoft's take on something like the Optimus Maximus, and consists of a large touchscreen display on top that "extends" to the keys below -- opening up a whole range of possibilities for different configurations and other shenanigans (no further technical details just yet, unfortunately). Head on past the break for a pair of demo videos and, if you're a student, hit up the source link below for the complete contest details -- act fast though, the deadline for applications is August 17th.



Thursday, August 12, 2010

Silverlight TV 40: You Are Already a Windows Phone Developer






Get Microsoft Silverlight


It has been said that if you know Silverlight then you are already a WindowsPhone 7 developer. Jesse Liberty joins John Papa this week to explore that statement and demonstrate the side-by-side creation of both a Silverlight application and a Windows Phone application.

Watch as Jesse cracks open Visual Studio 2010 and creates two similar applications: one for Silverlight and one for Windows Phone 7. He does this all from scratch so you get to see every step along the way.

Wednesday, August 11, 2010

Microsoft Research Reveals RearType QWERTY Input

For all Microsoft Research Lab fans, here is another idea from the team. See following article on Engadgets.
We've seen a few wacky split keyboards in our day, and even the occasional back-typing peripheral, but Microsoft Research has just congealed the core ideas into a why-didn't-I-think-of-that device for mobile use. Dubbed RearType, the QWERTY solution literally sticks a three-row keyboard on the back of a tablet PC, allowing users to have the same physical sensation as on laptop or desktop without taking up valuable touchscreen real estate. While there's still a few kinks to be worked out of the system (like how to set it down without triggering input) and no plans yet for commercial availability, a brief study showed users could attain 15WPM speeds on average with a single hour of training, and one participant managed to eke out a healthy 47WPM in the same timeframe. We imagine a certain Motorola device is feeling a mite jealous right about now. See the front of the (non-Microsoft) tablet right after the break, and read the full study at our more coverage link.

Sunday, August 8, 2010

C# FAQs Series: Using Proxy



In C# FAQs Series: We discuss most frequent questions asked on C# forums.
One of the most questions asked on C# froums is, how to use proxy settings in your own C# application.
You can programmatically change IE setting from registry using C#.
However the best way is to keep setting in your own application.
Updating IE settings:-

RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:8080");
Control Settings in C# Application:-

YourWebService ws=new YourWebService();
System.Net.NeworkCredential cr= new System.Net.NeworkCredential("User","pwd","domain");
System.Net.WebProxy pr=new System.Net.WebProxy ("127.0.1.2", 80);
pr.Credntials=cr;
ws.proxy=pr;
ws.MyAnyMethod();
To reset default settings...
pr.Credentials=System.Net.CredntialsCache.DefualtCrdentials;