Hi anirudhp,
Refer below sample.
Namespaces
C#
using System.Net;
VB.Net
Imports System.Net
Code
C#
Form1.cs
private void UploadFile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
var dialogResult = openFileDialog.ShowDialog();
if (dialogResult != DialogResult.OK) return;
Upload(openFileDialog.FileName);
}
private void Upload(string fileName)
{
var client = new WebClient();
var uri = new Uri("http://localhost:40814/209535_File%20Save%20From%20Windows%20To%20Web/Default.aspx");
{
client.Headers.Add("fileName", System.IO.Path.GetFileName(fileName));
client.UploadFileAsync(uri, fileName);
}
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs(Server.MapPath("~/Uploads/" + file.FileName));
}
}
VB.Net
Form1.vb
Private Sub UploadFile_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
Dim openFileDialog As OpenFileDialog = New OpenFileDialog()
Dim dialogResult = openFileDialog.ShowDialog()
If dialogResult <> dialogResult.OK Then Return
Upload(openFileDialog.FileName)
End Sub
Private Sub Upload(ByVal fileName As String)
Dim client = New WebClient()
Dim uri = New Uri("http://localhost:40814/209535_File%20Save%20From%20Windows%20To%20Web/Default.aspx")
If True Then
client.Headers.Add("fileName", System.IO.Path.GetFileName(fileName))
client.UploadFileAsync(uri, fileName)
End If
End Sub
Default.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
For Each f As String In Request.Files.AllKeys
Dim file As HttpPostedFile = Request.Files(f)
file.SaveAs(Server.MapPath("~/Uploads/" & file.FileName))
Next
End Sub