WebClient

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arash

    #1

    WebClient

    Hi everybody,
    I am trying to upload a file to my local server (http://mymachine) using
    the code below, what I get as error is:
    "... ---> System.Argument Exception: URI formats are not supported. ..."
    I have also tryed the destination without file name (ommiting "Cop.jpg") and
    got the same error. Please please help me.

    Regards
    Arash
    Code:

    private void btnUpload_Click (object sender, System.EventArg s e)

    {

    WebClient mClient = new WebClient();

    try{

    mClient.UploadF ile("D:\\Cop.jp g"," http://mymachine/Pars/Images/Cop.jpg ");

    }catch(Exceptio n el){

    MessageBox.Show ("Excep "+ el.ToString());

    }


  • Leon Jollans

    #2
    Re: WebClient

    have you tried using a remote url that is a web form that can handle the raw
    request data and save it? I don't know if that works, it's a guess.

    Additionally, in case what you're doing is the right way, have you
    definitely got write access to the directory in question?

    "Arash" <arashpirayande h@hotmail.com> wrote in message
    news:uJ3Sw2QfDH A.696@TK2MSFTNG P09.phx.gbl...[color=blue]
    > Hi everybody,
    > I am trying to upload a file to my local server (http://mymachine)[/color]
    using[color=blue]
    > the code below, what I get as error is:
    > "... ---> System.Argument Exception: URI formats are not supported.[/color]
    ...."[color=blue]
    > I have also tryed the destination without file name (ommiting "Cop.jpg")[/color]
    and[color=blue]
    > got the same error. Please please help me.
    >
    > Regards
    > Arash
    > Code:
    >
    > private void btnUpload_Click (object sender, System.EventArg s e)
    >
    > {
    >
    > WebClient mClient = new WebClient();
    >
    > try{
    >
    > mClient.UploadF ile("D:\\Cop.jp g"," http://mymachine/Pars/Images/Cop.jpg[/color]
    ");[color=blue]
    >
    > }catch(Exceptio n el){
    >
    > MessageBox.Show ("Excep "+ el.ToString());
    >
    > }
    >
    >[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: WebClient

      Arash,

      First, are you sure that your machine has support for accepting the
      file? You might want to use the overload that takes a parameter indicating
      which method to use, as it will allow you to specify "PUT" (which is what I
      believe you want based on the syntax you displayed).

      Finally, check the BaseAddress property of the WebClient. The address
      string that you pass into the method (for address parameter) is relative to
      this address.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - nicholas.paldin o@exisconsultin g.com

      "Arash" <arashpirayande h@hotmail.com> wrote in message
      news:uJ3Sw2QfDH A.696@TK2MSFTNG P09.phx.gbl...[color=blue]
      > Hi everybody,
      > I am trying to upload a file to my local server (http://mymachine)[/color]
      using[color=blue]
      > the code below, what I get as error is:
      > "... ---> System.Argument Exception: URI formats are not supported.[/color]
      ...."[color=blue]
      > I have also tryed the destination without file name (ommiting "Cop.jpg")[/color]
      and[color=blue]
      > got the same error. Please please help me.
      >
      > Regards
      > Arash
      > Code:
      >
      > private void btnUpload_Click (object sender, System.EventArg s e)
      >
      > {
      >
      > WebClient mClient = new WebClient();
      >
      > try{
      >
      > mClient.UploadF ile("D:\\Cop.jp g"," http://mymachine/Pars/Images/Cop.jpg[/color]
      ");[color=blue]
      >
      > }catch(Exceptio n el){
      >
      > MessageBox.Show ("Excep "+ el.ToString());
      >
      > }
      >
      >[/color]


      Comment

      Working...