如何在上传文件时使用webclient创建目录 [英] How to use webclient to create a directory when uploading a file

查看:223
本文介绍了如何在上传文件时使用webclient创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试下面的代码,在远程服务器上传文档,但它显示错误
"给定不支持路径格式。"




  using(WebClient client = new WebClient())

{


                  client.Credentials =新的NetworkCredential(用户名,密码);


             &NBSP ;    Directory.CreateDirectory(@" https://Sample.com/Folders/Test Folder /");    
//此处显示错误


     ;              client.UploadFile(QUOT; HTTPS://Sample.com/Folders/Test文件夹/"," POST",@" C:\\Sample Document.docx");   &NBSP ;            


  }



如何使用webclient创建必要的目录?


-TIA




解决方案

否/ p>

客户端无法在服务器上创建或进行任何修改,这是一个非常严重的问题!


一种典型的方式是你应该公开一个公共使用令牌访问接口。在验证时,只需在服务器端创建包含目录的文件夹(在某些开放服务中)。


【在客户端】

使用(WebClient客户端=新WebClient())
{

client.Credentials = new NetworkCredential(UserName,Password);
client.BaseAddress ="您的WebApi地址" ;;
}

【在服务器端】

 public void WebApiFunc(string name ......) 
{
//你要做什么验证名字?!
Directory.Create ......
}


Hi,

I am trying with below code, to Upload a document in remote server, but it shows an Error "The given path's format is not supported."


 using (WebClient client = new WebClient())
{

                  client.Credentials = new NetworkCredential(UserName, Password);

                  Directory.CreateDirectory(@"https://Sample.com/Folders/Test Folder/");     //Error shown here

                  client.UploadFile("https://Sample.com/Folders/Test Folder/", "POST" , @"C:\\Sample Document.docx");                

  }

How can I create the necessary directories with webclient ?

-TIA


解决方案

No.

A client cannot create or do any modifications onto a server, which is a very SERIOUS problem!

A typical way is that you should open a public access interface with a token. when validated, just do to create the folders with Directory at server side (in some open services).

【At the client side】

using (WebClient client = new WebClient())
{

                  client.Credentials = new NetworkCredential(UserName, Password);
                  client.BaseAddress = "Your Address of WebApi";
}

【At the server side】

public void WebApiFunc(string name……)
{
     //Do what you want to verify the name?!
     Directory.Create……
}


这篇关于如何在上传文件时使用webclient创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆