How to upload a file in c# console application

Showing Answers 1 - 3 of 3 Answers

Rajesh K

  • Feb 12th, 2007

We can do the File Upload process using System.IO namespace.It gives different method for handling File System Functionality as well as Directory Functionality.Using System.IOClass Test{ Public Void Main(String args[]){string FileUpload;string DestFolder;FileUpload=Console.ReadLine(); if (File.IsExists(FileUpload) && File.IsExists(DestFolder) ) {File.Copy(FileUpload,DestFolder); }else {Console.WriteLine("Please check the Source File or Destination Folder Exist"); }}}

  Was this answer useful?  Yes


  • Feb 15th, 2007

Use System.Net.WebClient Class use UploadFile method provided by the class. It accepts the Uri or string as destination and another parameter as location of file to be uploaded.

sandya Kolipaka

  • Nov 10th, 2016

static void Main(string[] args)
var wc = new WebClient();
byte[] response = wc.UploadFile("http:// mysite . com/Tests/Test", "POST", "teste.xml");
string s = System.Text.Encoding.ASCII.GetString(response);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions