Friday, 23 August 2013

Uploading screen winforms c#

Uploading screen winforms c#

We are making a program that downloads and uploads an xml(maximum 500kb)
file from a ftp server. we need to make an uploading screen. We tried
three methods. In the first method we used a .gif file which shows a
loading screen which we've put in a picture box. After that, before we
process the up-/download function, we make the picture box visible and
when the function finishes, we make it invisble. But it didn't work :(
here is the code:
private void button2_Click(object sender, EventArgs e)//upload button
{
picturebox1.visible=true; //.gif file
upload();
picturebox1.visible=false;
}
Here is the upload function:
void upload()
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://" +
IP + ":" + Port + downdest + xmlfile);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
//Load the file
FileStream stream = File.OpenRead("apartman.xml");
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
Using this code, uploading works but we dont see the picture. When the
upload code is not working we don't see the loading screen either.
Then we tried multithreading, but c# doesn't allow us to use this code in
a seperate thread.
picturebox1.visible=true;
It says something like: "you cannot also call this bla bla...". I don't
remember and also erased the code so sorry for the missing information.
Lastly we tred to use a backgroundworker, here is the code:
public Form1()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)//upload button
{
backgroundWorker1.RunWorkerAsync();
}
private void upload()
{
backgroundWorker1.ReportProgress(i);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
//upload
}
private void backgroundWorker1_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
MessageBox.Show("upload complete");
}
This code also gives an error message that states:
Error 1 Files has invalid value ""updates":". Illegal characters in path.xml2
Does anyone know the correct method of programming a loading screen?
If you need more details I can surely answer your questions.

No comments:

Post a Comment