Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

How to upload file from the local machine to webserver,and download its from the server to local machine .


1.Fileupload.aspx : for uploading files

Need two textbox controls

a.Uploading Folder FilePath(Enter the url of the website: Eg:

http://someserver/someapplication/receiver.aspx)

b.Enter the location of the local file location: Eg: c:\somefile.doc

2.FileDownload.aspx :downloading files


3.Reciever.aspx




using System.Net;
using System.IO;
using System.Text;

Fileupload.aspx


protected void cmdSend_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;

try
{
WebClient oclient = new WebClient();
byte[] responseArray = oclient.UploadFile(txtURLToSend.Text, "POST",

txtFileToSend.Text);
lblStatus.Text = "Check the file at " + Encoding.ASCII.GetString(responseArray);
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
}
}


FileDownload.aspx

using System.Net;
using System.IO;
using System.Text;

protected void cmdSend_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;

try
{
WebClient oclient = new WebClient();
byte[] responseArray = oclient.UploadFile(txtURLToSend.Text, "POST",

txtFileToSend.Text);
lblStatus.Text = "Check the file at " + Encoding.ASCII.GetString(responseArray);
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
}
}



create "ReceivedFiles" Folder in the Current Directory and create reciever.aspx file

Reciever.aspx


protected void Page_Load(object sender, System.EventArgs e)
{
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];

file.SaveAs(Server.MapPath("ReceivedFiles") + "\\" +

file.FileName);
}
}

tag:-How to upload file from the local machine to webserver,and download its from the server to local machine in ASP.NET using C#.NET