将文件从本地上载到远程URL服务器

时间:2013-04-05 08:02:05

标签: c# file-upload webclient streamwriter

我需要将文件上传到远程目录,但很难这样做。

请问任何想法或链接?

我尝试了网络客户端以及发布的文件上传方法。

我需要什么,例如是www.google.com\file\upload.txt,但我得C:\www.google.com\file\upload.txt

尝试1解决方案代码

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");
        }

尝试2解决方案代码

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());

此致

0 个答案:

没有答案