|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace SalvatoreCarlos.CodeProject.SerialDownloader.SDWinClient
{
public partial class Form1 : Form
{
string base64;
string localPath;
string remotePath;
string fileName;
public Form1()
{
InitializeComponent();
backgroundWorker1.DoWork += new DoWorkEventHandler(GetFile);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(GotFile);
}
void GotFile(object sender, RunWorkerCompletedEventArgs e)
{
byte[] base64Bytes = Convert.FromBase64String(this.base64);
FileStream stream = new FileStream(string.Format(@"{0}\{1}", localPath, fileName), FileMode.Create);
stream.Write(base64Bytes, 0, base64Bytes.Length);
stream.Close();
MessageBox.Show("Done !");
ToggleControl();
}
private void GetFile(object sender, DoWorkEventArgs e)
{
localhost.SDWebService service = new SalvatoreCarlos.CodeProject.SerialDownloader.SDWinClient.localhost.SDWebService();
this.base64 = service.GetBase64StringFromResource(this.remotePath);
}
private void ToggleControl()
{
this.txtRemoteFile.Enabled = !this.txtRemoteFile.Enabled;
this.btnFolderSelect.Enabled = !this.btnFolderSelect.Enabled;
this.btnStartDownload.Enabled = !this.btnStartDownload.Enabled;
}
private void btnStartDownload_Click(object sender, EventArgs e)
{
if (this.txtRemoteFile.Text == string.Empty || this.txtLocalPath.Text == string.Empty)
{
return;
}
this.remotePath = txtRemoteFile.Text;
fileName = remotePath.Substring(remotePath.LastIndexOf(@"/")+1);
ToggleControl();
this.backgroundWorker1.RunWorkerAsync();
}
private void btnFolderSelect_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
localPath = folderBrowserDialog1.SelectedPath;
txtLocalPath.Text = localPath;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.