Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to upload files to a remote directory but having difficulty in doing so.

Any idea or links please?

I have tried the web client and also the posted file upload approach.

What I need e.g. is www.google.com\file\upload.txt but i get C:\www.google.com\file\upload.txt

Try 1 Solution Code

C#
string filePaths = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "\\www.google.com\\file\\upload.txt");

using (StreamWriter writer = new StreamWriter(filePaths, true))
        {
            writer.Write("Word ");
            writer.WriteLine("word 2");
            writer.WriteLine("Line");
        }


Try 2 Solution Code

string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filePath = mydocpath + @"\upload.txt";
WebClient client = new WebClient();
Uri addy = new Uri("www.google.com\\file\\upload.txt");
byte[] arrReturn = client.UploadFile(addy, filePath);
Console.WriteLine(arrReturn.ToString());


Regards
Posted
Comments
ZurdoDev 5-Apr-13 7:59am    
Why aren't they working? Errors?
Naz_Firdouse 5-Apr-13 9:41am    
Please check this sample...
http://code.msdn.microsoft.com/CSASPNETRemoteUploadAndDown-a80b7cb5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900