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
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Monday, August 24, 2009
comments (0)
Labels:
C#.NET(ASP.NET)
Subscribe to:
Posts (Atom)